mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-28 04:55:37 -05:00
leverage global object creator in proxies.
This commit is contained in:
36
proxy/context.go
Normal file
36
proxy/context.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user