mirror of https://github.com/v2ray/v2ray-core
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.
24 lines
333 B
24 lines
333 B
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)
|
|
}
|