context.go 305 B

1234567891011121314151617
  1. package core
  2. import (
  3. "context"
  4. )
  5. type key int
  6. const v2rayKey key = 1
  7. // FromContext returns a Instance from the given context, or nil if the context doesn't contain one.
  8. func FromContext(ctx context.Context) *Instance {
  9. if s, ok := ctx.Value(v2rayKey).(*Instance); ok {
  10. return s
  11. }
  12. return nil
  13. }