github.com/xmidt-org/webpa-common@v1.11.9/secure/handler/context.go (about) 1 package handler 2 3 import "context" 4 5 type contextKey struct{} 6 7 //ContextValues contains the values shared under the satClientIDKey from this package 8 type ContextValues struct { 9 SatClientID string 10 Method string 11 Path string 12 PartnerIDs []string 13 Trust string 14 } 15 16 //NewContextWithValue returns a context with the specified context values 17 func NewContextWithValue(ctx context.Context, vals *ContextValues) context.Context { 18 return context.WithValue(ctx, contextKey{}, vals) 19 } 20 21 //FromContext returns ContextValues type (if any) along with a boolean that indicates whether 22 //the returned value is of the required/correct type for this package. 23 func FromContext(ctx context.Context) (*ContextValues, bool) { 24 vals, ofType := ctx.Value(contextKey{}).(*ContextValues) 25 return vals, ofType 26 }