Skip to content

Instantly share code, notes, and snippets.

@khepin
Created April 3, 2019 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khepin/50a1d26c4be058685b42b9b4ae232344 to your computer and use it in GitHub Desktop.
Save khepin/50a1d26c4be058685b42b9b4ae232344 to your computer and use it in GitHub Desktop.
package requestcontext
type RequestLogger struct{}
type User struct{}
type RequestContextValues struct {
Logger RequestLogger
User User
}
func WithRequestValues(ctx context.Context, vals RequestContextValues) context.Context {
return context.WithValue(ctx, "request_context_values", vals)
}
func GetRequestContextValues(ctx context.Context) RequestContextValues {
if vals, ok := ctx.Value("request_context_values").(RequestContextValues) {
return vals
}
return RequestContextValues{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment