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.
37 lines
757 B
37 lines
757 B
8 years ago
|
package proxy
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
type key int
|
||
|
|
||
|
const (
|
||
|
inboundMetaKey = key(0)
|
||
|
outboundMetaKey = key(1)
|
||
|
)
|
||
|
|
||
|
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)
|
||
|
}
|