Inappropriate key in call to `context.WithValue`
r0xdeadbeef opened this issue · 0 comments
r0xdeadbeef commented
handler_go17_test.go
should not use built-in type string as key for value; define your own type to avoid collisions
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.