From 102e32957a5a96ef208c602f546935d9f6b69bc1 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Fri, 2 Apr 2021 18:41:17 +0800 Subject: [PATCH] feat: export (const.)core.v2rayKey (#831) * comment on. * rename to V2rayKeyValue --- context.go | 5 +++-- functions.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index 84cd2396b..dd19b436f 100644 --- a/context.go +++ b/context.go @@ -9,11 +9,12 @@ import ( // V2rayKey is the key type of Instance in Context, exported for test. type V2rayKey int -const v2rayKey V2rayKey = 1 +// 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(v2rayKey).(*Instance); ok { + if s, ok := ctx.Value(V2rayKeyValue).(*Instance); ok { return s } return nil diff --git a/functions.go b/functions.go index d08091d8e..178e5dcbe 100644 --- a/functions.go +++ b/functions.go @@ -16,7 +16,7 @@ import ( func CreateObject(v *Instance, config interface{}) (interface{}, error) { var ctx context.Context if v != nil { - ctx = context.WithValue(v.ctx, v2rayKey, v) + ctx = context.WithValue(v.ctx, V2rayKeyValue, v) } return common.CreateObject(ctx, config) }