mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-08-15 03:14:38 -04:00
add jsonv5 conf loader
This commit is contained in:
@@ -2,6 +2,7 @@ package v5cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/golang/protobuf/proto"
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
"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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user