1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Fix json parsing dependency introduced by mutijson config

This commit is contained in:
Shelikhoo 2020-10-23 15:04:03 +01:00
parent 3c6e11673f
commit fd2638c522
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
3 changed files with 13 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import (
) )
type configFileLoader func(string) (io.Reader, error) type configFileLoader func(string) (io.Reader, error)
type extconfigLoader func([]string) (io.Reader, error) type extconfigLoader func([]string, io.Reader) (io.Reader, error)
var ( var (
EffectiveConfigFileLoader configFileLoader EffectiveConfigFileLoader configFileLoader
@ -25,10 +25,10 @@ func LoadConfig(file string) (io.Reader, error) {
// LoadExtConfig calls v2ctl to handle multiple config // LoadExtConfig calls v2ctl to handle multiple config
// the actual work also in external module // 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 { if EffectiveExtConfigLoader == nil {
return nil, newError("external config module not loaded").AtError() 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 return content, nil
} }
func ExtConfigLoader(files []string) (io.Reader, error) { func ExtConfigLoader(files []string, reader io.Reader) (io.Reader, error) {
buf, err := ctlcmd.Run(append([]string{"config"}, files...), os.Stdin) buf, err := ctlcmd.Run(append([]string{"config"}, files...), reader)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

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