godns/settings/settings.go

65 lines
2.0 KiB
Go

package settings
import (
"strconv"
)
type HostsSettings struct {
HostsFile string `toml:"host-file" env:"HOSTS_FILE"`
RedisEnable bool `toml:"redis-enable" env:"REDIS_HOSTS_ENABLE"`
RedisKey string `toml:"redis-key" env:"REDIS_HOSTS_KEY"`
TTL uint32 `toml:"ttl" env:"HOSTS_TTL"`
RefreshInterval uint32 `toml:"refresh-interval" env:"HOSTS_REFRESH_INTERVAL"`
}
type Settings struct {
Version string `toml:"version"`
Debug bool `toml:"debug"`
Server DNSServerSettings `toml:"server"`
ResolvConfig ResolvSettings `toml:"resolv"`
Redis RedisSettings `toml:"redis"`
Memcache MemcacheSettings `toml:"memcache"`
Log LogSettings `toml:"log"`
Cache CacheSettings `toml:"cache"`
Hosts HostsSettings `toml:"hosts"`
}
type ResolvSettings struct {
Timeout int `toml:"timeout" env:"RESOLV_TIMEOUT"`
Interval int `toml:"interval" env:"RESOLV_INTERVAL"`
SetEDNS0 bool `toml:"setedns0" env:"RESOLV_EDNS0"`
ServerListFile []string `toml:"server-list-file" env:"SERVER_LIST_FILE"`
ResolvFile string `toml:"resolv-file" env:"RESOLV_FILE"`
}
type DNSServerSettings struct {
Host string `toml:"host" env:"SERVER_BIND"`
Port int `toml:"port" env:"SERVER_PORT"`
}
type RedisSettings struct {
Host string `toml:"host" env:"REDIS_HOST"`
Port int `toml:"port" env:"REDIS_PORT"`
DB int `toml:"db" env:"REDIS_DB"`
Password string `toml:"password" env:"REDIS_PASSWORD"`
}
type MemcacheSettings struct {
Servers []string `toml:"servers" env:"MEMCACHE_SERVERS"`
}
func (s RedisSettings) Addr() string {
return s.Host + ":" + strconv.Itoa(s.Port)
}
type LogSettings struct {
Stdout bool `toml:"stdout" env:"LOG_STDOUT"`
File string `toml:"file" env:"LOG_FILE"`
Level string `toml:"level" env:"LOG_LEVEL"`
}
type CacheSettings struct {
Backend string `toml:"backend" env:"CACHE_BACKEND"`
Expire int `toml:"expire" env:"CACHE_EXPIRE"`
Maxcount int `toml:"maxcount" env:"CACHE_MAX_COUNT"`
}