Browse Source

revert: support yaml config

kslr 5 years ago
parent
commit
3c6e11673f

+ 0 - 4
go.mod

@@ -4,7 +4,6 @@ go 1.15
 
 
 require (
 require (
 	github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 // indirect
 	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/mock v1.4.4
 	github.com/golang/protobuf v1.4.3
 	github.com/golang/protobuf v1.4.3
 	github.com/google/go-cmp v0.5.2
 	github.com/google/go-cmp v0.5.2
@@ -26,6 +25,3 @@ require (
 	google.golang.org/protobuf v1.25.0
 	google.golang.org/protobuf v1.25.0
 	h12.io/socks v1.0.1
 	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

+ 3 - 2
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 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
 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.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/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/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=
 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/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 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
 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 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 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=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

+ 0 - 34
infra/conf/serial/loader.go

@@ -4,9 +4,6 @@ import (
 	"bytes"
 	"bytes"
 	"encoding/json"
 	"encoding/json"
 	"io"
 	"io"
-	"io/ioutil"
-
-	"github.com/ghodss/yaml"
 
 
 	"v2ray.com/core"
 	"v2ray.com/core"
 	"v2ray.com/core/common/errors"
 	"v2ray.com/core/common/errors"
@@ -70,22 +67,6 @@ func DecodeJSONConfig(reader io.Reader) (*conf.Config, error) {
 	return jsonConfig, nil
 	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) {
 func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
 	jsonConfig, err := DecodeJSONConfig(reader)
 	jsonConfig, err := DecodeJSONConfig(reader)
 	if err != nil {
 	if err != nil {
@@ -99,18 +80,3 @@ func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
 
 
 	return pbConfig, nil
 	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
-}

+ 0 - 6
main/distro/all/all.go

@@ -63,12 +63,6 @@ import (
 	// The following line loads JSON internally
 	// The following line loads JSON internally
 	// _ "v2ray.com/core/main/jsonem"
 	// _ "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)
 	// Load config from file or http(s)
 	_ "v2ray.com/core/main/confloader/external"
 	_ "v2ray.com/core/main/confloader/external"
 )
 )

+ 0 - 2
main/main.go

@@ -100,8 +100,6 @@ func GetConfigFormat() string {
 	switch strings.ToLower(*format) {
 	switch strings.ToLower(*format) {
 	case "pb", "protobuf":
 	case "pb", "protobuf":
 		return "protobuf"
 		return "protobuf"
-	case "yml", "yaml":
-		return "yaml"
 	default:
 	default:
 		return "json"
 		return "json"
 	}
 	}

+ 0 - 34
main/yaml/config_yaml.go

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

+ 0 - 9
main/yaml/errors.generated.go

@@ -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{})
-}

+ 0 - 9
main/yamlem/errors.generated.go

@@ -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{})
-}

+ 0 - 38
main/yamlem/yamlem.go

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