add client addr for auth plugin
This commit is contained in:
@ -5,11 +5,14 @@ import (
|
||||
)
|
||||
|
||||
type idKey struct{}
|
||||
|
||||
type ID string
|
||||
|
||||
type addrKey struct{}
|
||||
type ClientAddr string
|
||||
|
||||
var (
|
||||
clientIDKey = &idKey{}
|
||||
clientIDKey = &idKey{}
|
||||
clientAddrKey = &addrKey{}
|
||||
)
|
||||
|
||||
func ContextWithID(ctx context.Context, id ID) context.Context {
|
||||
@ -20,3 +23,12 @@ func IDFromContext(ctx context.Context) ID {
|
||||
v, _ := ctx.Value(clientIDKey).(ID)
|
||||
return v
|
||||
}
|
||||
|
||||
func ContextWithClientAddr(ctx context.Context, addr ClientAddr) context.Context {
|
||||
return context.WithValue(ctx, clientAddrKey, addr)
|
||||
}
|
||||
|
||||
func ClientAddrFromContext(ctx context.Context) ClientAddr {
|
||||
v, _ := ctx.Value(clientAddrKey).(ClientAddr)
|
||||
return v
|
||||
}
|
||||
|
Reference in New Issue
Block a user