From bc506ed3d99bc4b53fe5c1c948236141287b88aa Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 17 Oct 2022 19:07:45 +0800 Subject: [PATCH] feat: toml config support --- cmd/config/decode.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/config/decode.go b/cmd/config/decode.go index bb0543c..296571a 100644 --- a/cmd/config/decode.go +++ b/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)