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 {
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"`
}
}

30
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 {

4
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) {

8
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) {

18
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
}

34
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 {

5
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
)

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

Loading…
Cancel
Save