|
@ -8,13 +8,12 @@ import ( |
|
|
"XProxy/cmd/proxy" |
|
|
"XProxy/cmd/proxy" |
|
|
"XProxy/cmd/radvd" |
|
|
"XProxy/cmd/radvd" |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"github.com/BurntSushi/toml" |
|
|
log "github.com/sirupsen/logrus" |
|
|
log "github.com/sirupsen/logrus" |
|
|
"gopkg.in/yaml.v3" |
|
|
"gopkg.in/yaml.v3" |
|
|
"net/url" |
|
|
"net/url" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// TODO: add TOML support
|
|
|
|
|
|
|
|
|
|
|
|
type NetConfig struct { |
|
|
type NetConfig struct { |
|
|
Gateway string `yaml:"gateway" json:"gateway" toml:"gateway"` // network gateway
|
|
|
Gateway string `yaml:"gateway" json:"gateway" toml:"gateway"` // network gateway
|
|
|
Address string `yaml:"address" json:"address" toml:"address"` // network address
|
|
|
Address string `yaml:"address" json:"address" toml:"address"` // network address
|
|
@ -41,11 +40,15 @@ func configDecode(raw []byte, fileSuffix string) RawConfig { |
|
|
log.Debugf("Config raw content -> \n%s", string(raw)) |
|
|
log.Debugf("Config raw content -> \n%s", string(raw)) |
|
|
if fileSuffix == ".json" { |
|
|
if fileSuffix == ".json" { |
|
|
if err := json.Unmarshal(raw, &config); err != nil { // json format decode
|
|
|
if err := json.Unmarshal(raw, &config); err != nil { // json format decode
|
|
|
log.Panicf("Decode config file error -> %v", err) |
|
|
log.Panicf("Decode JSON config file error -> %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
} else if fileSuffix == ".toml" { |
|
|
|
|
|
if err := toml.Unmarshal(raw, &config); err != nil { // toml format decode
|
|
|
|
|
|
log.Panicf("Decode TOML config file error -> %v", err) |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if err := yaml.Unmarshal(raw, &config); err != nil { // yaml format decode
|
|
|
if err := yaml.Unmarshal(raw, &config); err != nil { // yaml format decode
|
|
|
log.Panicf("Decode config file error -> %v", err) |
|
|
log.Panicf("Decode YAML config file error -> %v", err) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
log.Debugf("Decoded configure -> %v", config) |
|
|
log.Debugf("Decoded configure -> %v", config) |
|
|