-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Currently SetUserValue accepts only a string for a key.
This is a limitation.
It would be great if the key accepted an interface{} similar to context.Context: https://pkg.go.dev/context#WithValue
The rationale for the (arguably backward compatible change) is that if it accepts interface{}, I can make the key into an unexported internal type.
That way, outside packages can't tamper with my user value.
In the fiber framework, the fiber context (which gives access to fasthttp.uservalue) is passed down middlewares. Some of these middleware are external packages I have no control over.
I need to protect some of my user values so they don't get tampered with. If the type of key is an unexported internal type, they can't modify it.
This approach is heavily used by context.Context.
type internalKey string
ctx.SetUserValue( internalKey("my key"), 22)