From 053e983c80df81839a52455dfce179a91afea70f Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 15 Oct 2022 18:12:59 +0800 Subject: [PATCH] feat: add toml tag --- cmd/asset/update.go | 8 ++++---- cmd/config/decode.go | 30 ++++++++++++++++-------------- cmd/custom/main.go | 4 ++-- cmd/dhcp/main.go | 8 ++++---- cmd/proxy/main.go | 18 +++++++++--------- cmd/radvd/radvd.go | 34 +++++++++++++++++----------------- go.mod | 5 ++++- go.sum | 2 ++ 8 files changed, 58 insertions(+), 51 deletions(-) diff --git a/cmd/asset/update.go b/cmd/asset/update.go index 0bf7597..3f0d492 100644 --- a/cmd/asset/update.go +++ b/cmd/asset/update.go @@ -8,11 +8,11 @@ import ( ) type Config struct { - Disable bool `yaml:"disable" json:"disable"` + Disable bool `yaml:"disable" json:"disable" toml:"disable"` Update struct { - Proxy string `yaml:"proxy" json:"proxy"` - Cron string `yaml:"cron" json:"cron"` - Url map[string]string `yaml:"url" json:"url"` + Proxy string `yaml:"proxy" json:"proxy" toml:"proxy"` + Cron string `yaml:"cron" json:"cron" toml:"cron"` + Url map[string]string `yaml:"url" json:"url" toml:"url"` } } diff --git a/cmd/config/decode.go b/cmd/config/decode.go index 23a2a1c..bb0543c 100644 --- a/cmd/config/decode.go +++ b/cmd/config/decode.go @@ -13,25 +13,27 @@ import ( "net/url" ) +// TODO: add TOML support + type NetConfig struct { - Gateway string `yaml:"gateway" json:"gateway"` // network gateway - Address string `yaml:"address" json:"address"` // network address + Gateway string `yaml:"gateway" json:"gateway" toml:"gateway"` // network gateway + Address string `yaml:"address" json:"address" toml:"address"` // network address } type RawConfig struct { - Asset asset.Config `yaml:"asset" json:"asset"` - Radvd radvd.Config `yaml:"radvd" json:"radvd"` - DHCP dhcp.Config `yaml:"dhcp" json:"dhcp"` - Proxy proxy.Config `yaml:"proxy" json:"proxy"` - Custom custom.Config `yaml:"custom" json:"custom"` + Asset asset.Config `yaml:"asset" json:"asset" toml:"asset"` + Radvd radvd.Config `yaml:"radvd" json:"radvd" toml:"radvd"` + DHCP dhcp.Config `yaml:"dhcp" json:"dhcp" toml:"dhcp"` + Proxy proxy.Config `yaml:"proxy" json:"proxy" toml:"proxy"` + Custom custom.Config `yaml:"custom" json:"custom" toml:"custom"` Network struct { - Dev string `yaml:"dev" json:"dev"` - DNS []string `yaml:"dns" json:"dns"` - ByPass []string `yaml:"bypass" json:"bypass"` - Exclude []string `yaml:"exclude" json:"exclude"` - IPv4 NetConfig `yaml:"ipv4" json:"ipv4"` - IPv6 NetConfig `yaml:"ipv6" json:"ipv6"` - } `yaml:"network" json:"network"` + Dev string `yaml:"dev" json:"dev" toml:"dev"` + DNS []string `yaml:"dns" json:"dns" toml:"dns"` + ByPass []string `yaml:"bypass" json:"bypass" toml:"bypass"` + Exclude []string `yaml:"exclude" json:"exclude" toml:"exclude"` + IPv4 NetConfig `yaml:"ipv4" json:"ipv4" toml:"ipv4"` + IPv6 NetConfig `yaml:"ipv6" json:"ipv6" toml:"ipv6"` + } `yaml:"network" json:"network" toml:"network"` } func configDecode(raw []byte, fileSuffix string) RawConfig { diff --git a/cmd/custom/main.go b/cmd/custom/main.go index 4aa2022..9e360dc 100644 --- a/cmd/custom/main.go +++ b/cmd/custom/main.go @@ -7,8 +7,8 @@ import ( ) type Config struct { - Pre []string `yaml:"pre" json:"pre"` - Post []string `yaml:"post" json:"post"` + Pre []string `yaml:"pre" json:"pre" toml:"pre"` + Post []string `yaml:"post" json:"post" toml:"post"` } func runScript(command string) { diff --git a/cmd/dhcp/main.go b/cmd/dhcp/main.go index d9a6472..de5ca4f 100644 --- a/cmd/dhcp/main.go +++ b/cmd/dhcp/main.go @@ -9,13 +9,13 @@ import ( var WorkDir = "/etc/dhcp" type dhcpConfig struct { - Enable bool `yaml:"enable" json:"enable"` - Configure string `yaml:"config" json:"config"` + Enable bool `yaml:"enable" json:"enable" toml:"enable"` + Configure string `yaml:"config" json:"config" toml:"config"` } type Config struct { - IPv4 dhcpConfig `yaml:"ipv4" json:"ipv4"` - IPv6 dhcpConfig `yaml:"ipv6" json:"ipv6"` + IPv4 dhcpConfig `yaml:"ipv4" json:"ipv4" toml:"ipv4"` + IPv6 dhcpConfig `yaml:"ipv6" json:"ipv6" toml:"ipv6"` } func Load(config *Config) { diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index 01ddcd0..82172f8 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -7,16 +7,16 @@ import ( ) type Config struct { - Log string `yaml:"log" json:"log"` - Core string `yaml:"core" json:"core"` - Http map[string]int `yaml:"http" json:"http"` - Socks map[string]int `yaml:"socks" json:"socks"` - AddOn []interface{} `yaml:"addon" json:"addon"` + Log string `yaml:"log" json:"log" toml:"log"` + Core string `yaml:"core" json:"core" toml:"core"` + Http map[string]int `yaml:"http" json:"http" toml:"http"` + Socks map[string]int `yaml:"socks" json:"socks" toml:"socks"` + AddOn []interface{} `yaml:"addon" json:"addon" toml:"addon"` Sniff struct { - Enable bool `yaml:"enable" json:"enable"` - Redirect bool `yaml:"redirect" json:"redirect"` - Exclude []string `yaml:"exclude" json:"exclude"` - } `yaml:"sniff" json:"sniff"` + Enable bool `yaml:"enable" json:"enable" toml:"enable"` + Redirect bool `yaml:"redirect" json:"redirect" toml:"redirect"` + Exclude []string `yaml:"exclude" json:"exclude" toml:"exclude"` + } `yaml:"sniff" json:"sniff" toml:"sniff"` V4TProxyPort int V6TProxyPort int } diff --git a/cmd/radvd/radvd.go b/cmd/radvd/radvd.go index bdc9a14..c84e914 100644 --- a/cmd/radvd/radvd.go +++ b/cmd/radvd/radvd.go @@ -7,27 +7,27 @@ import ( ) type Config struct { - Log int `yaml:"log" json:"log"` - Dev string `yaml:"dev" json:"dev"` - Enable bool `yaml:"enable" json:"enable"` - Client []string `yaml:"client" json:"client"` - Option map[string]string `yaml:"option" json:"option"` + Log int `yaml:"log" json:"log" toml:"log"` + Dev string `yaml:"dev" json:"dev" toml:"dev"` + Enable bool `yaml:"enable" json:"enable" toml:"enable"` + Client []string `yaml:"client" json:"client" toml:"client"` + Option map[string]string `yaml:"option" json:"option" toml:"option"` Route struct { - Cidr string `yaml:"cidr" json:"cidr"` - Option map[string]string `yaml:"option" json:"option"` - } `yaml:"route" json:"route"` + Cidr string `yaml:"cidr" json:"cidr" toml:"cidr"` + Option map[string]string `yaml:"option" json:"option" toml:"option"` + } `yaml:"route" json:"route" toml:"route"` Prefix struct { - Cidr string `yaml:"cidr" json:"cidr"` - Option map[string]string `yaml:"option" json:"option"` - } `yaml:"prefix" json:"prefix"` + Cidr string `yaml:"cidr" json:"cidr" toml:"cidr"` + Option map[string]string `yaml:"option" json:"option" toml:"option"` + } `yaml:"prefix" json:"prefix" toml:"prefix"` DNSSL struct { // DNS Search List - Suffix []string `yaml:"suffix" json:"suffix"` - Option map[string]string `yaml:"option" json:"option"` - } `yaml:"dnssl" json:"dnssl"` + Suffix []string `yaml:"suffix" json:"suffix" toml:"suffix"` + Option map[string]string `yaml:"option" json:"option" toml:"option"` + } `yaml:"dnssl" json:"dnssl" toml:"dnssl"` RDNSS struct { // Recursive DNS Server - IP []string `yaml:"ip" json:"ip"` - Option map[string]string `yaml:"option" json:"option"` - } `yaml:"rdnss" json:"rdnss"` + IP []string `yaml:"ip" json:"ip" toml:"ip"` + Option map[string]string `yaml:"option" json:"option" toml:"option"` + } `yaml:"rdnss" json:"rdnss" toml:"rdnss"` } func genSpace(num int) string { diff --git a/go.mod b/go.mod index dd3323e..b474ebf 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 ) -require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect +require ( + github.com/BurntSushi/toml v1.2.0 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect +) diff --git a/go.sum b/go.sum index 793c0a0..3f4e737 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= +github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=