1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 00:06:11 -04:00
v2fly/proxy/context.go

50 lines
1023 B
Go
Raw Normal View History

package proxy
import (
"context"
)
type key int
const (
2017-01-14 18:48:37 -05:00
inboundMetaKey key = iota
outboundMetaKey
dialerKey
)
func ContextWithInboundMeta(ctx context.Context, meta *InboundHandlerMeta) context.Context {
return context.WithValue(ctx, inboundMetaKey, meta)
}
func InboundMetaFromContext(ctx context.Context) *InboundHandlerMeta {
v := ctx.Value(inboundMetaKey)
if v == nil {
return nil
}
return v.(*InboundHandlerMeta)
}
func ContextWithOutboundMeta(ctx context.Context, meta *OutboundHandlerMeta) context.Context {
return context.WithValue(ctx, outboundMetaKey, meta)
}
func OutboundMetaFromContext(ctx context.Context) *OutboundHandlerMeta {
v := ctx.Value(outboundMetaKey)
if v == nil {
return nil
}
return v.(*OutboundHandlerMeta)
}
2017-01-14 18:48:37 -05:00
func ContextWithDialer(ctx context.Context, dialer Dialer) context.Context {
return context.WithValue(ctx, dialerKey, dialer)
}
func DialerFromContext(ctx context.Context) Dialer {
v := ctx.Value(dialerKey)
if v == nil {
return nil
}
return v.(Dialer)
}