mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
Remove unused
This commit is contained in:
parent
ea94d07f65
commit
a4f657f787
@ -35,8 +35,6 @@ var ReaderDecoderByFormat = make(map[string]readerDecoder)
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ReaderDecoderByFormat["json"] = DecodeJSONConfig
|
ReaderDecoderByFormat["json"] = DecodeJSONConfig
|
||||||
ReaderDecoderByFormat["yaml"] = DecodeYAMLConfig
|
|
||||||
ReaderDecoderByFormat["toml"] = DecodeTOMLConfig
|
|
||||||
|
|
||||||
core.ConfigBuilderForFiles = BuildConfig
|
core.ConfigBuilderForFiles = BuildConfig
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,11 @@ package serial
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
|
||||||
"github.com/pelletier/go-toml"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/infra/conf"
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
json_reader "github.com/xtls/xray-core/infra/conf/json"
|
json_reader "github.com/xtls/xray-core/infra/conf/json"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type offset struct {
|
type offset struct {
|
||||||
@ -83,68 +79,3 @@ func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
|
|||||||
|
|
||||||
return pbConfig, nil
|
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
|
|
||||||
}
|
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
_ "github.com/xtls/xray-core/app/proxyman/outbound"
|
_ "github.com/xtls/xray-core/app/proxyman/outbound"
|
||||||
|
|
||||||
// Default commander and all its services. This is an optional feature.
|
// Default commander and all its services. This is an optional feature.
|
||||||
_ "github.com/xtls/xray-core/app/commander"
|
//_ "github.com/xtls/xray-core/app/commander"
|
||||||
_ "github.com/xtls/xray-core/app/log/command"
|
//_ "github.com/xtls/xray-core/app/log/command"
|
||||||
_ "github.com/xtls/xray-core/app/proxyman/command"
|
//_ "github.com/xtls/xray-core/app/proxyman/command"
|
||||||
_ "github.com/xtls/xray-core/app/stats/command"
|
//_ "github.com/xtls/xray-core/app/stats/command"
|
||||||
|
|
||||||
// Other optional features.
|
// Other optional features.
|
||||||
_ "github.com/xtls/xray-core/app/dns"
|
_ "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/freedom"
|
||||||
_ "github.com/xtls/xray-core/proxy/http"
|
_ "github.com/xtls/xray-core/proxy/http"
|
||||||
_ "github.com/xtls/xray-core/proxy/loopback"
|
_ "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/shadowsocks"
|
||||||
_ "github.com/xtls/xray-core/proxy/socks"
|
_ "github.com/xtls/xray-core/proxy/socks"
|
||||||
_ "github.com/xtls/xray-core/proxy/trojan"
|
_ "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/wechat"
|
||||||
_ "github.com/xtls/xray-core/transport/internet/headers/wireguard"
|
_ "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/json"
|
||||||
_ "github.com/xtls/xray-core/main/toml"
|
|
||||||
_ "github.com/xtls/xray-core/main/yaml"
|
|
||||||
|
|
||||||
// Load config from file or http(s)
|
// Load config from file or http(s)
|
||||||
_ "github.com/xtls/xray-core/main/confloader/external"
|
//_ "github.com/xtls/xray-core/main/confloader/external"
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
_ "github.com/xtls/xray-core/main/commands/all"
|
//_ "github.com/xtls/xray-core/main/commands/all"
|
||||||
)
|
)
|
||||||
|
@ -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{})
|
|
||||||
}
|
|
@ -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")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
|
@ -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{})
|
|
||||||
}
|
|
@ -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")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user