From a4f657f7879be4ce59d3f7c3d1e1a090d40dc689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 19 Sep 2021 20:28:38 +0800 Subject: [PATCH] Remove unused --- infra/conf/serial/builder.go | 2 - infra/conf/serial/loader.go | 71 +---------------------------------- main/distro/all/all.go | 19 ++++------ main/toml/errors.generated.go | 9 ----- main/toml/toml.go | 48 ----------------------- main/yaml/errors.generated.go | 9 ----- main/yaml/yaml.go | 48 ----------------------- 7 files changed, 8 insertions(+), 198 deletions(-) delete mode 100644 main/toml/errors.generated.go delete mode 100644 main/toml/toml.go delete mode 100644 main/yaml/errors.generated.go delete mode 100644 main/yaml/yaml.go diff --git a/infra/conf/serial/builder.go b/infra/conf/serial/builder.go index 443dbdb0..84b07c7f 100644 --- a/infra/conf/serial/builder.go +++ b/infra/conf/serial/builder.go @@ -35,8 +35,6 @@ var ReaderDecoderByFormat = make(map[string]readerDecoder) func init() { ReaderDecoderByFormat["json"] = DecodeJSONConfig - ReaderDecoderByFormat["yaml"] = DecodeYAMLConfig - ReaderDecoderByFormat["toml"] = DecodeTOMLConfig core.ConfigBuilderForFiles = BuildConfig } diff --git a/infra/conf/serial/loader.go b/infra/conf/serial/loader.go index 9195c6f7..2959a63d 100644 --- a/infra/conf/serial/loader.go +++ b/infra/conf/serial/loader.go @@ -3,15 +3,11 @@ package serial import ( "bytes" "encoding/json" - "io" - - "github.com/ghodss/yaml" - "github.com/pelletier/go-toml" - "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/core" "github.com/xtls/xray-core/infra/conf" json_reader "github.com/xtls/xray-core/infra/conf/json" + "io" ) type offset struct { @@ -83,68 +79,3 @@ func LoadJSONConfig(reader io.Reader) (*core.Config, error) { return pbConfig, nil } - -// DecodeTOMLConfig reads from reader and decode the config into *conf.Config -// using github.com/pelletier/go-toml and map to convert toml to json. -func DecodeTOMLConfig(reader io.Reader) (*conf.Config, error) { - tomlFile, err := io.ReadAll(reader) - if err != nil { - return nil, newError("failed to read config file").Base(err) - } - - configMap := make(map[string]interface{}) - if err := toml.Unmarshal(tomlFile, &configMap); err != nil { - return nil, newError("failed to convert toml to map").Base(err) - } - - jsonFile, err := json.Marshal(&configMap) - if err != nil { - return nil, newError("failed to convert map to json").Base(err) - } - - return DecodeJSONConfig(bytes.NewReader(jsonFile)) -} - -func LoadTOMLConfig(reader io.Reader) (*core.Config, error) { - tomlConfig, err := DecodeTOMLConfig(reader) - if err != nil { - return nil, err - } - - pbConfig, err := tomlConfig.Build() - if err != nil { - return nil, newError("failed to parse toml config").Base(err) - } - - return pbConfig, nil -} - -// DecodeYAMLConfig reads from reader and decode the config into *conf.Config -// using github.com/ghodss/yaml to convert yaml to json. -func DecodeYAMLConfig(reader io.Reader) (*conf.Config, error) { - yamlFile, err := io.ReadAll(reader) - if err != nil { - return nil, newError("failed to read config file").Base(err) - } - - jsonFile, err := yaml.YAMLToJSON(yamlFile) - if err != nil { - return nil, newError("failed to convert yaml to json").Base(err) - } - - return DecodeJSONConfig(bytes.NewReader(jsonFile)) -} - -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 -} diff --git a/main/distro/all/all.go b/main/distro/all/all.go index 3653329a..38defc6d 100644 --- a/main/distro/all/all.go +++ b/main/distro/all/all.go @@ -9,10 +9,10 @@ import ( _ "github.com/xtls/xray-core/app/proxyman/outbound" // Default commander and all its services. This is an optional feature. - _ "github.com/xtls/xray-core/app/commander" - _ "github.com/xtls/xray-core/app/log/command" - _ "github.com/xtls/xray-core/app/proxyman/command" - _ "github.com/xtls/xray-core/app/stats/command" + //_ "github.com/xtls/xray-core/app/commander" + //_ "github.com/xtls/xray-core/app/log/command" + //_ "github.com/xtls/xray-core/app/proxyman/command" + //_ "github.com/xtls/xray-core/app/stats/command" // Other optional features. _ "github.com/xtls/xray-core/app/dns" @@ -33,7 +33,7 @@ import ( _ "github.com/xtls/xray-core/proxy/freedom" _ "github.com/xtls/xray-core/proxy/http" _ "github.com/xtls/xray-core/proxy/loopback" - _ "github.com/xtls/xray-core/proxy/mtproto" + //_ "github.com/xtls/xray-core/proxy/mtproto" _ "github.com/xtls/xray-core/proxy/shadowsocks" _ "github.com/xtls/xray-core/proxy/socks" _ "github.com/xtls/xray-core/proxy/trojan" @@ -63,14 +63,9 @@ import ( _ "github.com/xtls/xray-core/transport/internet/headers/wechat" _ "github.com/xtls/xray-core/transport/internet/headers/wireguard" - // JSON & TOML & YAML _ "github.com/xtls/xray-core/main/json" - _ "github.com/xtls/xray-core/main/toml" - _ "github.com/xtls/xray-core/main/yaml" - // Load config from file or http(s) - _ "github.com/xtls/xray-core/main/confloader/external" - + //_ "github.com/xtls/xray-core/main/confloader/external" // Commands - _ "github.com/xtls/xray-core/main/commands/all" + //_ "github.com/xtls/xray-core/main/commands/all" ) diff --git a/main/toml/errors.generated.go b/main/toml/errors.generated.go deleted file mode 100644 index 0bad202e..00000000 --- a/main/toml/errors.generated.go +++ /dev/null @@ -1,9 +0,0 @@ -package toml - -import "github.com/xtls/xray-core/common/errors" - -type errPathObjHolder struct{} - -func newError(values ...interface{}) *errors.Error { - return errors.New(values...).WithPathObj(errPathObjHolder{}) -} diff --git a/main/toml/toml.go b/main/toml/toml.go deleted file mode 100644 index e52077f3..00000000 --- a/main/toml/toml.go +++ /dev/null @@ -1,48 +0,0 @@ -package toml - -import ( - "io" - - "github.com/xtls/xray-core/common" - "github.com/xtls/xray-core/common/cmdarg" - "github.com/xtls/xray-core/core" - "github.com/xtls/xray-core/infra/conf" - "github.com/xtls/xray-core/infra/conf/serial" - "github.com/xtls/xray-core/main/confloader" -) - -func init() { - common.Must(core.RegisterConfigLoader(&core.ConfigFormat{ - Name: "TOML", - Extension: []string{"toml"}, - Loader: func(input interface{}) (*core.Config, error) { - switch v := input.(type) { - case cmdarg.Arg: - cf := &conf.Config{} - for i, arg := range v { - newError("Reading config: ", arg).AtInfo().WriteToLog() - r, err := confloader.LoadConfig(arg) - if err != nil { - return nil, newError("failed to read config: ", arg).Base(err) - } - c, err := serial.DecodeTOMLConfig(r) - if err != nil { - return nil, newError("failed to decode config: ", arg).Base(err) - } - if i == 0 { - // This ensure even if the muti-json parser do not support a setting, - // It is still respected automatically for the first configure file - *cf = *c - continue - } - cf.Override(c, arg) - } - return cf.Build() - case io.Reader: - return serial.LoadTOMLConfig(v) - default: - return nil, newError("unknow type") - } - }, - })) -} diff --git a/main/yaml/errors.generated.go b/main/yaml/errors.generated.go deleted file mode 100644 index c4da8fa9..00000000 --- a/main/yaml/errors.generated.go +++ /dev/null @@ -1,9 +0,0 @@ -package yaml - -import "github.com/xtls/xray-core/common/errors" - -type errPathObjHolder struct{} - -func newError(values ...interface{}) *errors.Error { - return errors.New(values...).WithPathObj(errPathObjHolder{}) -} diff --git a/main/yaml/yaml.go b/main/yaml/yaml.go deleted file mode 100644 index 760a5717..00000000 --- a/main/yaml/yaml.go +++ /dev/null @@ -1,48 +0,0 @@ -package yaml - -import ( - "io" - - "github.com/xtls/xray-core/common" - "github.com/xtls/xray-core/common/cmdarg" - "github.com/xtls/xray-core/core" - "github.com/xtls/xray-core/infra/conf" - "github.com/xtls/xray-core/infra/conf/serial" - "github.com/xtls/xray-core/main/confloader" -) - -func init() { - common.Must(core.RegisterConfigLoader(&core.ConfigFormat{ - Name: "YAML", - Extension: []string{"yaml", "yml"}, - Loader: func(input interface{}) (*core.Config, error) { - switch v := input.(type) { - case cmdarg.Arg: - cf := &conf.Config{} - for i, arg := range v { - newError("Reading config: ", arg).AtInfo().WriteToLog() - r, err := confloader.LoadConfig(arg) - if err != nil { - return nil, newError("failed to read config: ", arg).Base(err) - } - c, err := serial.DecodeYAMLConfig(r) - if err != nil { - return nil, newError("failed to decode config: ", arg).Base(err) - } - if i == 0 { - // This ensure even if the muti-json parser do not support a setting, - // It is still respected automatically for the first configure file - *cf = *c - continue - } - cf.Override(c, arg) - } - return cf.Build() - case io.Reader: - return serial.LoadYAMLConfig(v) - default: - return nil, newError("unknow type") - } - }, - })) -}