|
@@ -2,6 +2,7 @@ package v5cfg
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
|
|
+ "encoding/json"
|
|
|
"github.com/golang/protobuf/proto"
|
|
"github.com/golang/protobuf/proto"
|
|
|
core "github.com/v2fly/v2ray-core/v4"
|
|
core "github.com/v2fly/v2ray-core/v4"
|
|
|
"github.com/v2fly/v2ray-core/v4/app/dispatcher"
|
|
"github.com/v2fly/v2ray-core/v4/app/dispatcher"
|
|
@@ -71,3 +72,18 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) {
|
|
|
}
|
|
}
|
|
|
return config, nil
|
|
return config, nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func loadJsonConfig(data []byte) (*core.Config, error) {
|
|
|
|
|
+ rootConfig := &RootConfig{}
|
|
|
|
|
+
|
|
|
|
|
+ err := json.Unmarshal(data, rootConfig)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, newError("unable to load json").Base(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ message, err := rootConfig.BuildV5(context.TODO())
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, newError("unable to build config").Base(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ return message.(*core.Config), nil
|
|
|
|
|
+}
|