Hacker News new | ask | show | jobs
by shorsher 2116 days ago
Here's a question from someone who is recently out of school and somewhat new to Go. Is it OK to use Context for request-scoped values? i.e. passing data between middleware? I have started doing this, but is there a better alternative?

Peter Bourgon's blog post[0] about context made me think it is fine. After reading the comments here, I am not so sure. Especially since his post was roughly 4 years ago.

0: https://peter.bourgon.org/blog/2016/07/11/context.html

1 comments

I liked the following blog post where Jack Lindamood argues pretty convincingly against using Context.Value in nearly all circumstances, and gives some nice alternatives.

https://medium.com/@cep21/how-to-correctly-use-context-conte...