1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-18 13:35:23 +00:00
v2fly/context.go
rurirei 102e32957a
feat: export (const.)core.v2rayKey (#831)
* comment on.

* rename to V2rayKeyValue
2021-04-02 18:41:17 +08:00

31 lines
724 B
Go

// +build !confonly
package core
import (
"context"
)
// V2rayKey is the key type of Instance in Context, exported for test.
type V2rayKey int
// V2rayKeyValue is the key value of Instance in Context, exported for test.
const V2rayKeyValue V2rayKey = 1
// FromContext returns an Instance from the given context, or nil if the context doesn't contain one.
func FromContext(ctx context.Context) *Instance {
if s, ok := ctx.Value(V2rayKeyValue).(*Instance); ok {
return s
}
return nil
}
// MustFromContext returns an Instance from the given context, or panics if not present.
func MustFromContext(ctx context.Context) *Instance {
v := FromContext(ctx)
if v == nil {
panic("V is not in context.")
}
return v
}