mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
Fix json parsing dependency introduced by mutijson config
This commit is contained in:
parent
3c6e11673f
commit
fd2638c522
@ -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)
|
||||
}
|
||||
|
4
main/confloader/external/external.go
vendored
4
main/confloader/external/external.go
vendored
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
Loading…
Reference in New Issue
Block a user