Browse Source

feat: add toml tag

v1.x.x
Dnomd343 2 years ago
parent
commit
053e983c80
  1. 8
      cmd/asset/update.go
  2. 30
      cmd/config/decode.go
  3. 4
      cmd/custom/main.go
  4. 8
      cmd/dhcp/main.go
  5. 18
      cmd/proxy/main.go
  6. 34
      cmd/radvd/radvd.go
  7. 5
      go.mod
  8. 2
      go.sum

8
cmd/asset/update.go

@ -8,11 +8,11 @@ import (
) )
type Config struct { type Config struct {
Disable bool `yaml:"disable" json:"disable"` Disable bool `yaml:"disable" json:"disable" toml:"disable"`
Update struct { Update struct {
Proxy string `yaml:"proxy" json:"proxy"` Proxy string `yaml:"proxy" json:"proxy" toml:"proxy"`
Cron string `yaml:"cron" json:"cron"` Cron string `yaml:"cron" json:"cron" toml:"cron"`
Url map[string]string `yaml:"url" json:"url"` Url map[string]string `yaml:"url" json:"url" toml:"url"`
} }
} }

30
cmd/config/decode.go

@ -13,25 +13,27 @@ import (
"net/url" "net/url"
) )
// TODO: add TOML support
type NetConfig struct { type NetConfig struct {
Gateway string `yaml:"gateway" json:"gateway"` // network gateway Gateway string `yaml:"gateway" json:"gateway" toml:"gateway"` // network gateway
Address string `yaml:"address" json:"address"` // network address Address string `yaml:"address" json:"address" toml:"address"` // network address
} }
type RawConfig struct { type RawConfig struct {
Asset asset.Config `yaml:"asset" json:"asset"` Asset asset.Config `yaml:"asset" json:"asset" toml:"asset"`
Radvd radvd.Config `yaml:"radvd" json:"radvd"` Radvd radvd.Config `yaml:"radvd" json:"radvd" toml:"radvd"`
DHCP dhcp.Config `yaml:"dhcp" json:"dhcp"` DHCP dhcp.Config `yaml:"dhcp" json:"dhcp" toml:"dhcp"`
Proxy proxy.Config `yaml:"proxy" json:"proxy"` Proxy proxy.Config `yaml:"proxy" json:"proxy" toml:"proxy"`
Custom custom.Config `yaml:"custom" json:"custom"` Custom custom.Config `yaml:"custom" json:"custom" toml:"custom"`
Network struct { Network struct {
Dev string `yaml:"dev" json:"dev"` Dev string `yaml:"dev" json:"dev" toml:"dev"`
DNS []string `yaml:"dns" json:"dns"` DNS []string `yaml:"dns" json:"dns" toml:"dns"`
ByPass []string `yaml:"bypass" json:"bypass"` ByPass []string `yaml:"bypass" json:"bypass" toml:"bypass"`
Exclude []string `yaml:"exclude" json:"exclude"` Exclude []string `yaml:"exclude" json:"exclude" toml:"exclude"`
IPv4 NetConfig `yaml:"ipv4" json:"ipv4"` IPv4 NetConfig `yaml:"ipv4" json:"ipv4" toml:"ipv4"`
IPv6 NetConfig `yaml:"ipv6" json:"ipv6"` IPv6 NetConfig `yaml:"ipv6" json:"ipv6" toml:"ipv6"`
} `yaml:"network" json:"network"` } `yaml:"network" json:"network" toml:"network"`
} }
func configDecode(raw []byte, fileSuffix string) RawConfig { func configDecode(raw []byte, fileSuffix string) RawConfig {

4
cmd/custom/main.go

@ -7,8 +7,8 @@ import (
) )
type Config struct { type Config struct {
Pre []string `yaml:"pre" json:"pre"` Pre []string `yaml:"pre" json:"pre" toml:"pre"`
Post []string `yaml:"post" json:"post"` Post []string `yaml:"post" json:"post" toml:"post"`
} }
func runScript(command string) { func runScript(command string) {

8
cmd/dhcp/main.go

@ -9,13 +9,13 @@ import (
var WorkDir = "/etc/dhcp" var WorkDir = "/etc/dhcp"
type dhcpConfig struct { type dhcpConfig struct {
Enable bool `yaml:"enable" json:"enable"` Enable bool `yaml:"enable" json:"enable" toml:"enable"`
Configure string `yaml:"config" json:"config"` Configure string `yaml:"config" json:"config" toml:"config"`
} }
type Config struct { type Config struct {
IPv4 dhcpConfig `yaml:"ipv4" json:"ipv4"` IPv4 dhcpConfig `yaml:"ipv4" json:"ipv4" toml:"ipv4"`
IPv6 dhcpConfig `yaml:"ipv6" json:"ipv6"` IPv6 dhcpConfig `yaml:"ipv6" json:"ipv6" toml:"ipv6"`
} }
func Load(config *Config) { func Load(config *Config) {

18
cmd/proxy/main.go

@ -7,16 +7,16 @@ import (
) )
type Config struct { type Config struct {
Log string `yaml:"log" json:"log"` Log string `yaml:"log" json:"log" toml:"log"`
Core string `yaml:"core" json:"core"` Core string `yaml:"core" json:"core" toml:"core"`
Http map[string]int `yaml:"http" json:"http"` Http map[string]int `yaml:"http" json:"http" toml:"http"`
Socks map[string]int `yaml:"socks" json:"socks"` Socks map[string]int `yaml:"socks" json:"socks" toml:"socks"`
AddOn []interface{} `yaml:"addon" json:"addon"` AddOn []interface{} `yaml:"addon" json:"addon" toml:"addon"`
Sniff struct { Sniff struct {
Enable bool `yaml:"enable" json:"enable"` Enable bool `yaml:"enable" json:"enable" toml:"enable"`
Redirect bool `yaml:"redirect" json:"redirect"` Redirect bool `yaml:"redirect" json:"redirect" toml:"redirect"`
Exclude []string `yaml:"exclude" json:"exclude"` Exclude []string `yaml:"exclude" json:"exclude" toml:"exclude"`
} `yaml:"sniff" json:"sniff"` } `yaml:"sniff" json:"sniff" toml:"sniff"`
V4TProxyPort int V4TProxyPort int
V6TProxyPort int V6TProxyPort int
} }

34
cmd/radvd/radvd.go

@ -7,27 +7,27 @@ import (
) )
type Config struct { type Config struct {
Log int `yaml:"log" json:"log"` Log int `yaml:"log" json:"log" toml:"log"`
Dev string `yaml:"dev" json:"dev"` Dev string `yaml:"dev" json:"dev" toml:"dev"`
Enable bool `yaml:"enable" json:"enable"` Enable bool `yaml:"enable" json:"enable" toml:"enable"`
Client []string `yaml:"client" json:"client"` Client []string `yaml:"client" json:"client" toml:"client"`
Option map[string]string `yaml:"option" json:"option"` Option map[string]string `yaml:"option" json:"option" toml:"option"`
Route struct { Route struct {
Cidr string `yaml:"cidr" json:"cidr"` Cidr string `yaml:"cidr" json:"cidr" toml:"cidr"`
Option map[string]string `yaml:"option" json:"option"` Option map[string]string `yaml:"option" json:"option" toml:"option"`
} `yaml:"route" json:"route"` } `yaml:"route" json:"route" toml:"route"`
Prefix struct { Prefix struct {
Cidr string `yaml:"cidr" json:"cidr"` Cidr string `yaml:"cidr" json:"cidr" toml:"cidr"`
Option map[string]string `yaml:"option" json:"option"` Option map[string]string `yaml:"option" json:"option" toml:"option"`
} `yaml:"prefix" json:"prefix"` } `yaml:"prefix" json:"prefix" toml:"prefix"`
DNSSL struct { // DNS Search List DNSSL struct { // DNS Search List
Suffix []string `yaml:"suffix" json:"suffix"` Suffix []string `yaml:"suffix" json:"suffix" toml:"suffix"`
Option map[string]string `yaml:"option" json:"option"` Option map[string]string `yaml:"option" json:"option" toml:"option"`
} `yaml:"dnssl" json:"dnssl"` } `yaml:"dnssl" json:"dnssl" toml:"dnssl"`
RDNSS struct { // Recursive DNS Server RDNSS struct { // Recursive DNS Server
IP []string `yaml:"ip" json:"ip"` IP []string `yaml:"ip" json:"ip" toml:"ip"`
Option map[string]string `yaml:"option" json:"option"` Option map[string]string `yaml:"option" json:"option" toml:"option"`
} `yaml:"rdnss" json:"rdnss"` } `yaml:"rdnss" json:"rdnss" toml:"rdnss"`
} }
func genSpace(num int) string { func genSpace(num int) string {

5
go.mod

@ -8,4 +8,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 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
)

2
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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

Loading…
Cancel
Save