mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
21 lines
447 B
Go
21 lines
447 B
Go
package envctx
|
|
|
|
import "context"
|
|
|
|
type environmentContextKey int
|
|
|
|
const (
|
|
environmentKey environmentContextKey = iota
|
|
)
|
|
|
|
func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context {
|
|
return context.WithValue(ctx, environmentKey, environment)
|
|
}
|
|
|
|
func EnvironmentFromContext(ctx context.Context) interface{} {
|
|
if environment, ok := ctx.Value(environmentKey).(interface{}); ok {
|
|
return environment
|
|
}
|
|
return nil
|
|
}
|