I'm avoiding context.WithValue since I feel the objects I'm dealing with 
are too "powerful" (i.e. not simple Values). For a read, a 2016 article on 
this : https://peter.bourgon.org/blog/2016/07/11/context.html
I remember reading through another article saying the usage of WithValue is 
kind of risky when time goes on, since it's just a magical interface{} 
store. Performance-wise I'm not sure though.

Though, you're right, that'd be another way to do it. Waiting for people to 
chime in with their ideas too (hopefully!) :)


Le lundi 23 septembre 2019 11:20:52 UTC+2, Andrew Pillar a écrit :
>
> Why don't you use context.WithValue(r.Context(), <key>, <value>) for 
> passing 
> the injected values you want to your HTTP handlers. Then defer the logic 
> for 
> retrieving whatever you want for that handler to a middleware function. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c23761e8-1287-4758-8303-b39db8cf22f0%40googlegroups.com.

Reply via email to