1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/common/protocol/context.go

24 lines
333 B
Go

package protocol
import (
"context"
)
type key int
const (
userKey key = iota
)
func ContextWithUser(ctx context.Context, user *User) context.Context {
return context.WithValue(ctx, userKey, user)
}
func UserFromContext(ctx context.Context) *User {
v := ctx.Value(userKey)
if v == nil {
return nil
}
return v.(*User)
}