Merge pull request #351 from v2fly/dev-fix-mutijson-dep

Fix json parsing dependency introduced by mutijson config
This commit is contained in:
Xiaokang Wang 2020-10-26 15:44:58 +00:00 committed by GitHub
commit 3684dc15de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -6,7 +6,7 @@ import (
)
type configFileLoader func(string) (io.Reader, error)
type extconfigLoader func([]string) (io.Reader, error)
type extconfigLoader func([]string, io.Reader) (io.Reader, error)
var (
EffectiveConfigFileLoader configFileLoader
@ -25,10 +25,10 @@ func LoadConfig(file string) (io.Reader, error) {
// LoadExtConfig calls v2ctl to handle multiple config
// the actual work also in external module
func LoadExtConfig(files []string) (io.Reader, error) {
func LoadExtConfig(files []string, reader io.Reader) (io.Reader, error) {
if EffectiveExtConfigLoader == nil {
return nil, newError("external config module not loaded").AtError()
}
return EffectiveExtConfigLoader(files)
return EffectiveExtConfigLoader(files, reader)
}

View File

@ -72,8 +72,8 @@ func FetchHTTPContent(target string) ([]byte, error) {
return content, nil
}
func ExtConfigLoader(files []string) (io.Reader, error) {
buf, err := ctlcmd.Run(append([]string{"config"}, files...), os.Stdin)
func ExtConfigLoader(files []string, reader io.Reader) (io.Reader, error) {
buf, err := ctlcmd.Run(append([]string{"config"}, files...), reader)
if err != nil {
return nil, err
}

View File

@ -4,11 +4,11 @@ package json
import (
"io"
"os"
"v2ray.com/core"
"v2ray.com/core/common"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/infra/conf/serial"
"v2ray.com/core/main/confloader"
)
@ -19,15 +19,19 @@ func init() {
Loader: func(input interface{}) (*core.Config, error) {
switch v := input.(type) {
case cmdarg.Arg:
r, err := confloader.LoadExtConfig(v)
r, err := confloader.LoadExtConfig(v, os.Stdin)
if err != nil {
return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
}
return core.LoadConfig("protobuf", "", r)
case io.Reader:
return serial.LoadJSONConfig(v)
r, err := confloader.LoadExtConfig([]string{"stdin:"}, os.Stdin)
if err != nil {
return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
}
return core.LoadConfig("protobuf", "", r)
default:
return nil, newError("unknow type")
return nil, newError("unknown type")
}
},
}))