Skip to content

Commit

Permalink
Fix json parsing dependency introduced by mutijson config
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Oct 23, 2020
1 parent 3c6e116 commit fd2638c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions main/confloader/confloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 2 additions & 2 deletions main/confloader/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 8 additions & 5 deletions main/json/config_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
}
},
}))
Expand Down

0 comments on commit fd2638c

Please sign in to comment.