mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-03 00:22:05 +00:00
abstract type for conf load func
This commit is contained in:
1 parent
61e95e06c0
commit
1bb34bfe17
5 files changed
+95
-57
No files matched your search
+19
-15
@@ -2,7 +2,6 @@ package jsonem
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/cmdarg"
|
||||
"v2ray.com/core/infra/conf"
|
||||
"v2ray.com/core/infra/conf/serial"
|
||||
)
|
||||
@@ -21,21 +21,25 @@ func init() {
|
||||
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
||||
Name: "JSON",
|
||||
Extension: []string{"json"},
|
||||
Loader: func(input io.Reader) (*core.Config, error) {
|
||||
fns := []string{}
|
||||
data, _ := ioutil.ReadAll(input)
|
||||
json.Unmarshal(data, &fns)
|
||||
|
||||
cf := &conf.Config{}
|
||||
for _, arg := range fns {
|
||||
r, err := LoadArg(arg)
|
||||
common.Must(err)
|
||||
c, err := serial.DecodeJSONConfig(r)
|
||||
common.Must(err)
|
||||
cf.Override(c, arg)
|
||||
Loader: func(input interface{}) (*core.Config, error) {
|
||||
switch v := input.(type) {
|
||||
case cmdarg.Arg:
|
||||
cf := &conf.Config{}
|
||||
for _, arg := range v {
|
||||
r, err := LoadArg(arg)
|
||||
common.Must(err)
|
||||
c, err := serial.DecodeJSONConfig(r)
|
||||
common.Must(err)
|
||||
cf.Override(c, arg)
|
||||
}
|
||||
return cf.Build()
|
||||
case io.Reader:
|
||||
return serial.LoadJSONConfig(v)
|
||||
default:
|
||||
return nil, newError("unknow type")
|
||||
}
|
||||
return cf.Build()
|
||||
}}))
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
func LoadArg(arg string) (out io.Reader, err error) {
|
||||
|
||||
Reference in new issue
Block a user