mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-09 12:58:40 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
core
29
core/context.go
Normal file
29
core/context.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// +build !confonly
|
||||
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// XrayKey is the key type of Instance in Context, exported for test.
|
||||
type XrayKey int
|
||||
|
||||
const xrayKey XrayKey = 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(xrayKey).(*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 {
|
||||
x := FromContext(ctx)
|
||||
if x == nil {
|
||||
panic("X is not in context.")
|
||||
}
|
||||
return x
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue