Browse Source

feat: toml config support

v1.x.x
Dnomd343 2 years ago
parent
commit
bc506ed3d9
  1. 11
      cmd/config/decode.go

11
cmd/config/decode.go

@ -8,13 +8,12 @@ import (
"XProxy/cmd/proxy"
"XProxy/cmd/radvd"
"encoding/json"
"github.com/BurntSushi/toml"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"net/url"
)
// TODO: add TOML support
type NetConfig struct {
Gateway string `yaml:"gateway" json:"gateway" toml:"gateway"` // network gateway
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))
if fileSuffix == ".json" {
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 {
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)

Loading…
Cancel
Save