mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 08:19:23 +02:00
fix context keys
This commit is contained in:
parent
7adda15c75
commit
e6fe3b0ceb
3 changed files with 16 additions and 9 deletions
|
@ -11,16 +11,16 @@ import (
|
|||
|
||||
const headerName = "x-request-id"
|
||||
|
||||
var contextKey struct{}
|
||||
type contextKey struct{}
|
||||
|
||||
// WithValue returns a new context from the parent context with a request id value set.
|
||||
func WithValue(parent context.Context, requestID string) context.Context {
|
||||
return context.WithValue(parent, contextKey, requestID)
|
||||
return context.WithValue(parent, contextKey{}, requestID)
|
||||
}
|
||||
|
||||
// FromContext gets the request id from a context.
|
||||
func FromContext(ctx context.Context) string {
|
||||
if id, ok := ctx.Value(contextKey).(string); ok {
|
||||
if id, ok := ctx.Value(contextKey{}).(string); ok {
|
||||
return id
|
||||
}
|
||||
return ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue