Search posts, tags, users, and pages
Paul Di Gian
The Golang standard library comes with a simple interface, context.Context, which is a little harder to understand and use than the others. The difficulties in getting the context.Context interface may be the naming, maybe not super appropriate. In t...
Sergey Sarbash
Going Go
Dealing with context I usually use efficient zero memory allocation struct{}-based keys. For example:
struct{}
type ReqIDKey struct{} ... ctx := context.WithValue(r.Context(), ReqIDKey{}, reqID)
Thanks, it is indeed a great suggestion! I will incorporate it!
Sergey Sarbash
Going Go
Dealing with context I usually use efficient zero memory allocation
struct{}-based keys. For example:type ReqIDKey struct{} ... ctx := context.WithValue(r.Context(), ReqIDKey{}, reqID)