Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inappropriate key in call to context.WithValue #65

Open
raheel0x01 opened this issue Aug 17, 2022 · 0 comments
Open

Inappropriate key in call to context.WithValue #65

raheel0x01 opened this issue Aug 17, 2022 · 0 comments

Comments

@raheel0x01
Copy link

handler_go17_test.go

should not use built-in type string as key for value; define your own type to avoid collisions

image

Description

To prevent clashes across packages using context, the provided key must be similar and should not be of type string or any other built-in type. Users of WithValue must provide their key types.

To avoid allocating when assigning to an interface{}, context keys often have concrete type struct{}. Alternatively, exported context key variables’ static type should be a pointer or interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant