github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/profile/context.go (about) 1 package profile 2 3 import ( 4 "context" 5 ) 6 7 // CtxKey defines a distinct type for context keys used by the profile 8 // package 9 type CtxKey string 10 11 // profileCtxKey is the key for adding a profile identifier to a context.Context 12 const profileCtxKey CtxKey = "Profile" 13 14 // AddIDToContext adds a token string to a context 15 func AddIDToContext(ctx context.Context, s string) context.Context { 16 return context.WithValue(ctx, profileCtxKey, s) 17 } 18 19 // IDFromCtx extracts a profile identifier from a given context if one is set 20 func IDFromCtx(ctx context.Context) string { 21 i := ctx.Value(profileCtxKey) 22 if s, ok := i.(string); ok { 23 return s 24 } 25 return "" 26 }