Created
April 3, 2019 18:45
-
-
Save khepin/50a1d26c4be058685b42b9b4ae232344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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