FILE / ScuroNeko/mtg

raw_config.go

Исходный файл и его история в репозитории.
FILE 015f02c077f485ec08ffbb813991f0c03871b21f
Files
mtg/raw_config.go
T

64 lines
1.6 KiB
Go

package main
import (
"fmt"
"io"
"github.com/pelletier/go-toml"
)
type rawConfig struct {
Debug bool `toml:"debug"`
Secret string `toml:"secret"`
BindTo string `toml:"bind-to"`
TCPBuffer string `toml:"tcp-buffer"`
PreferIP string `toml:"prefer-ip"`
CloakPort uint `toml:"cloak-port"`
Probes struct {
Time struct {
Enabled bool `toml:"enabled"`
AllowSkewness string `toml:"allow-skewness"`
} `toml:"time"`
AntiReplay struct {
Enabled bool `toml:"enabled"`
MaxSize string `toml:"max-size"`
TTL string `toml:"ttl"`
} `toml:"anti-replay"`
} `toml:"probes"`
Network struct {
PublicIP struct {
IPv4 string `toml:"ipv4"`
IPv6 string `toml:"ipv6"`
} `toml:"public-ip"`
Dialers struct {
Telegram string `toml:"telegram"`
Default string `toml:"default"`
} `toml:"dialers"`
DOHHostname string `toml:"doh-hostname"`
Proxies []string `toml:"proxies"`
} `toml:"network"`
Stats struct {
StatsD struct {
Enabled bool `toml:"enabled"`
Address string `toml:"address"`
MetricPrefix string `toml:"metric-prefix"`
} `toml:"statsd"`
Prometheus struct {
Enabled bool `toml:"enabled"`
BindTo string `toml:"bind-to"`
HttpPath string `toml:"http-path"`
MetricPrefix string `toml:"metric-prefix"`
} `toml:"prometheus"`
} `toml:"stats"`
}
func parseRawConfig(reader io.Reader) (*rawConfig, error) {
conf := &rawConfig{}
if err := toml.NewDecoder(reader).Decode(conf); err != nil {
return nil, fmt.Errorf("cannot parse config: %w", err)
}
return conf, nil
}