Support loading config from different formats (#228)

This commit is contained in:
Monsoon 2021-02-12 22:12:58 +08:00 committed by GitHub
parent 96d7156eba
commit 1b87264c53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 30 deletions

View file

@ -11,7 +11,6 @@ import (
"regexp"
"runtime"
"runtime/debug"
"strings"
"syscall"
"github.com/xtls/xray-core/common/cmdarg"
@ -158,30 +157,25 @@ func getConfigFilePath() cmdarg.Arg {
}
func getConfigFormat() string {
switch strings.ToLower(*format) {
case "pb", "protobuf":
return "protobuf"
case "yaml", "yml":
return "yaml"
case "toml":
return "toml"
default:
return "json"
f := core.GetFormatByExtension(*format)
if f == "" {
f = "json"
}
return f
}
func startXray() (core.Server, error) {
configFiles := getConfigFilePath()
config, err := core.LoadConfig(getConfigFormat(), configFiles[0], configFiles)
//config, err := core.LoadConfig(getConfigFormat(), configFiles[0], configFiles)
//config, err := core.LoadConfigs(getConfigFormat(), configFiles)
c, err := core.LoadConfig(getConfigFormat(), configFiles)
if err != nil {
return nil, newError("failed to load config files: [", configFiles.String(), "]").Base(err)
}
server, err := core.New(config)
server, err := core.New(c)
if err != nil {
return nil, newError("failed to create server").Base(err)
}