File size: 502 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package apikey

import "context"

type contextKey int

const (
	contextKeyPolicy contextKey = iota
)

// PolicyFromContext returns the Policy associated with the given context.
func PolicyFromContext(ctx context.Context) *GQLPolicy {
	p, _ := ctx.Value(contextKeyPolicy).(*GQLPolicy)
	return p
}

// ContextWithPolicy returns a new context with the given Policy attached.
func ContextWithPolicy(ctx context.Context, p *GQLPolicy) context.Context {
	return context.WithValue(ctx, contextKeyPolicy, p)
}