1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Add create object with environment api

This commit is contained in:
Shelikhoo 2022-02-07 22:10:58 +00:00 committed by Xiaokang Wang (Shelikhoo)
parent 7888c10622
commit 49ea72d0ed

View File

@ -3,6 +3,7 @@ package core
import ( import (
"bytes" "bytes"
"context" "context"
"github.com/v2fly/v2ray-core/v5/common/environment/envctx"
"github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/net" "github.com/v2fly/v2ray-core/v5/common/net"
@ -12,10 +13,15 @@ import (
// CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil. // CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
func CreateObject(v *Instance, config interface{}) (interface{}, error) { func CreateObject(v *Instance, config interface{}) (interface{}, error) {
return CreateObjectWithEnvironment(v, config, nil)
}
func CreateObjectWithEnvironment(v *Instance, config, environment interface{}) (interface{}, error) {
var ctx context.Context var ctx context.Context
if v != nil { if v != nil {
ctx = toContext(v.ctx, v) ctx = toContext(v.ctx, v)
} }
ctx = envctx.ContextWithEnvironment(ctx, environment)
return common.CreateObject(ctx, config) return common.CreateObject(ctx, config)
} }