From fd2638c522dc8c13dd6891af0f399e31a8dac3e6 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Fri, 23 Oct 2020 15:04:03 +0100 Subject: [PATCH] Fix json parsing dependency introduced by mutijson config --- main/confloader/confloader.go | 6 +++--- main/confloader/external/external.go | 4 ++-- main/json/config_json.go | 13 ++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/main/confloader/confloader.go b/main/confloader/confloader.go index d52b5b89e..24da1a0cb 100644 --- a/main/confloader/confloader.go +++ b/main/confloader/confloader.go @@ -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) } diff --git a/main/confloader/external/external.go b/main/confloader/external/external.go index 84c00cbe9..1c4145e1a 100644 --- a/main/confloader/external/external.go +++ b/main/confloader/external/external.go @@ -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 } diff --git a/main/json/config_json.go b/main/json/config_json.go index 650aceb51..8f55b5853 100644 --- a/main/json/config_json.go +++ b/main/json/config_json.go @@ -4,11 +4,10 @@ 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 +18,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") } }, }))