3 ms·
Don't create a custom context type. This will make it more difficult to interop with any other library that uses the normal context.Context.[0] Furthermore, wh
by assbuttbuttass 3y ago
Don't create a custom context type. This will make it more difficult to interop with any other library that uses the normal context.Context.[0]
Furthermore, why is that code using string keys for the context? It's recommended in the context package documentation that context keys should always be an unexported type, so that the key can never collide with a different key.[1] It's common to define accessor functions which are type safe
[0] https://google.github.io/styleguide/go/decisions.html#custom-contexts https://google.github.io/styleguide/go/decisions.html#custom...
[1] https://pkg.go.dev/context#WithValue https://pkg.go.dev/context#WithValue
- raviatluri 3y agoAgreed, custom context types don’t work for libraries. But, i am finding them useful in building a pipeline composer similar to https://www.reddit.com/r/RedditEng/comments/z137m3/from_service_to_platform_a_ranking_system_in_go/ https://www.reddit.com/r/RedditEng/comments/z137m3/from_serv...