You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
896 B

package jwt
import "golang.org/x/net/context"
type userIdKey struct{}
type authKey struct{}
type needAuthKey struct{}
func SetUserContext(ctx context.Context, user *UserInfo) context.Context {
return context.WithValue(ctx, userIdKey{}, user)
}
func FromUserContext(ctx context.Context) (user *UserInfo, ok bool) {
user, ok = ctx.Value(userIdKey{}).(*UserInfo)
return
}
func SetAuthKeyContext(ctx context.Context, key string) context.Context {
return context.WithValue(ctx, authKey{}, key)
}
func FromAuthKeyContext(ctx context.Context) string {
v := ctx.Value(authKey{})
if v == nil {
return ""
}
return v.(string)
}
func SetNeedAuthContext(ctx context.Context, auth bool) context.Context {
return context.WithValue(ctx, needAuthKey{}, auth)
}
func FromNeedAuthContext(ctx context.Context) bool {
v := ctx.Value(needAuthKey{})
if v == nil {
return false
}
return v.(bool)
}