mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
revert: support yaml config
This commit is contained in:
parent
2aedff1218
commit
3c6e11673f
4
go.mod
4
go.mod
@ -4,7 +4,6 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 // indirect
|
||||
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
|
||||
github.com/golang/mock v1.4.4
|
||||
github.com/golang/protobuf v1.4.3
|
||||
github.com/google/go-cmp v0.5.2
|
||||
@ -26,6 +25,3 @@ require (
|
||||
google.golang.org/protobuf v1.25.0
|
||||
h12.io/socks v1.0.1
|
||||
)
|
||||
|
||||
// override gopkg.in/yaml.v2 version defined in github.com/ghodss/yaml
|
||||
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.3.0
|
||||
|
5
go.sum
5
go.sum
@ -39,8 +39,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
|
||||
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
|
||||
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
@ -309,6 +307,9 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/common/errors"
|
||||
@ -70,22 +67,6 @@ func DecodeJSONConfig(reader io.Reader) (*conf.Config, error) {
|
||||
return jsonConfig, nil
|
||||
}
|
||||
|
||||
// DecodeYAMLConfig reads from reader and decode the config into *conf.Config
|
||||
// syntax error could NOT be detected.
|
||||
func DecodeYAMLConfig(reader io.Reader) (*conf.Config, error) {
|
||||
yamlConfig := &conf.Config{}
|
||||
|
||||
// Since v2ray use json.RawMessage a lot, so we use a wrapper to convert yaml to json
|
||||
if tmpBuf, err := ioutil.ReadAll(reader); err != nil {
|
||||
return nil, newError("failed to read").Base(err)
|
||||
} else if err := yaml.Unmarshal(tmpBuf, yamlConfig); err != nil {
|
||||
return nil, newError("failed to parse config").Base(err)
|
||||
}
|
||||
|
||||
return yamlConfig, nil
|
||||
}
|
||||
|
||||
// LoadJSONConfig uses content in reader to return a core.Config
|
||||
func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
|
||||
jsonConfig, err := DecodeJSONConfig(reader)
|
||||
if err != nil {
|
||||
@ -99,18 +80,3 @@ func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
|
||||
|
||||
return pbConfig, nil
|
||||
}
|
||||
|
||||
// LoadYAMLConfig uses content in reader to return a core.Config
|
||||
func LoadYAMLConfig(reader io.Reader) (*core.Config, error) {
|
||||
yamlConfig, err := DecodeYAMLConfig(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pbConfig, err := yamlConfig.Build()
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse yaml config").Base(err)
|
||||
}
|
||||
|
||||
return pbConfig, nil
|
||||
}
|
||||
|
@ -63,12 +63,6 @@ import (
|
||||
// The following line loads JSON internally
|
||||
// _ "v2ray.com/core/main/jsonem"
|
||||
|
||||
// YAML config support. Choose only one from the two below.
|
||||
// The following line loads YAML from v2ctl
|
||||
_ "v2ray.com/core/main/yaml"
|
||||
// The following line loads YAML internally
|
||||
// _ "v2ray.com/core/main/yamlem"
|
||||
|
||||
// Load config from file or http(s)
|
||||
_ "v2ray.com/core/main/confloader/external"
|
||||
)
|
||||
|
@ -100,8 +100,6 @@ func GetConfigFormat() string {
|
||||
switch strings.ToLower(*format) {
|
||||
case "pb", "protobuf":
|
||||
return "protobuf"
|
||||
case "yml", "yaml":
|
||||
return "yaml"
|
||||
default:
|
||||
return "json"
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
package yaml
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/cmdarg"
|
||||
"v2ray.com/core/infra/conf/serial"
|
||||
"v2ray.com/core/main/confloader"
|
||||
)
|
||||
|
||||
//go:generate go run v2ray.com/core/common/errors/errorgen
|
||||
|
||||
func init() {
|
||||
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
||||
Name: "YAML",
|
||||
Extension: []string{"yml", "yaml"},
|
||||
Loader: func(input interface{}) (*core.Config, error) {
|
||||
switch v := input.(type) {
|
||||
case cmdarg.Arg:
|
||||
r, err := confloader.LoadExtConfig(v)
|
||||
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.LoadYAMLConfig(v)
|
||||
default:
|
||||
return nil, newError("unknow type")
|
||||
}
|
||||
},
|
||||
}))
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package yaml
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package yamlem
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package yamlem
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/cmdarg"
|
||||
"v2ray.com/core/infra/conf"
|
||||
"v2ray.com/core/infra/conf/serial"
|
||||
"v2ray.com/core/main/confloader"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
||||
Name: "YAML",
|
||||
Extension: []string{"yml", "yaml"},
|
||||
Loader: func(input interface{}) (*core.Config, error) {
|
||||
switch v := input.(type) {
|
||||
case cmdarg.Arg:
|
||||
cf := &conf.Config{}
|
||||
for _, arg := range v {
|
||||
newError("Reading config: ", arg).AtInfo().WriteToLog()
|
||||
r, err := confloader.LoadConfig(arg)
|
||||
common.Must(err)
|
||||
c, err := serial.DecodeYAMLConfig(r)
|
||||
common.Must(err)
|
||||
cf.Override(c, arg)
|
||||
}
|
||||
return cf.Build()
|
||||
case io.Reader:
|
||||
return serial.LoadYAMLConfig(v)
|
||||
default:
|
||||
return nil, newError("unknow type")
|
||||
}
|
||||
},
|
||||
}))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user