|
|
@@ -28,17 +28,35 @@ func MustFromContext(ctx context.Context) *Instance {
|
|
|
return v
|
|
|
}
|
|
|
|
|
|
-// ToContext returns ctx from the given context, or creates an Instance if the context doesn't find that.
|
|
|
-func ToContext(ctx context.Context, v *Instance) context.Context {
|
|
|
+/* toContext returns ctx from the given context, or creates an Instance if the context doesn't find that.
|
|
|
+
|
|
|
+It is unsupported to use this function to create a context that is suitable to invoke V2Ray's internal component
|
|
|
+in third party code, you shouldn't use //go:linkname to alias of this function into your own package and
|
|
|
+use this function in your third party code.
|
|
|
+
|
|
|
+For third party code, usage enabled by creating a context to interact with V2Ray's internal component is unsupported,
|
|
|
+and may break at any time.
|
|
|
+
|
|
|
+*/
|
|
|
+func toContext(ctx context.Context, v *Instance) context.Context {
|
|
|
if FromContext(ctx) != v {
|
|
|
ctx = context.WithValue(ctx, v2rayKey, v)
|
|
|
}
|
|
|
return ctx
|
|
|
}
|
|
|
|
|
|
-// MustToContext returns ctx from the given context, or panics if not found that.
|
|
|
-func MustToContext(ctx context.Context, v *Instance) context.Context {
|
|
|
- if c := ToContext(ctx, v); c != ctx {
|
|
|
+/* mustToContext returns ctx from the given context, or panics if not found that.
|
|
|
+
|
|
|
+It is unsupported to use this function to create a context that is suitable to invoke V2Ray's internal component
|
|
|
+in third party code, you shouldn't use //go:linkname to alias of this function into your own package and
|
|
|
+use this function in your third party code.
|
|
|
+
|
|
|
+For third party code, usage enabled by creating a context to interact with V2Ray's internal component is unsupported,
|
|
|
+and may break at any time.
|
|
|
+
|
|
|
+*/
|
|
|
+func mustToContext(ctx context.Context, v *Instance) context.Context {
|
|
|
+ if c := toContext(ctx, v); c != ctx {
|
|
|
panic("V is not in context.")
|
|
|
}
|
|
|
return ctx
|