mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-09-23 10:44:03 -04:00
help function for create instance from config bytes
This commit is contained in:
19
functions.go
19
functions.go
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
)
|
||||
|
||||
// CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
|
||||
@@ -15,6 +16,24 @@ func CreateObject(v *Instance, config interface{}) (interface{}, error) {
|
||||
return common.CreateObject(ctx, config)
|
||||
}
|
||||
|
||||
// StartInstance starts a new V2Ray instance with given serialized config, and return a handle for shutting down the instance.
|
||||
func StartInstance(configFormat string, configBytes []byte) (common.Closable, error) {
|
||||
var mb buf.MultiBuffer
|
||||
common.Must2(mb.Write(configBytes))
|
||||
config, err := LoadConfig(configFormat, "", &mb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
instance, err := New(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := instance.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return instance, nil
|
||||
}
|
||||
|
||||
func PrintDeprecatedFeatureWarning(feature string) {
|
||||
newError("You are using a deprecated feature: " + feature + ". Please update your config file with latest configuration format, or update your client software.").WriteToLog()
|
||||
}
|
||||
|
Reference in New Issue
Block a user