godns/settings.go

80 lines
1.4 KiB
Go
Raw Normal View History

2013-07-23 11:10:38 +00:00
package main
import (
"flag"
"fmt"
"os"
2013-07-26 10:54:19 +00:00
"strconv"
"github.com/BurntSushi/toml"
2013-07-23 11:10:38 +00:00
)
var (
settings Settings
)
type Settings struct {
Version string
Debug bool
Server DNSServerSettings `toml:"server"`
ResolvConfig ResolvSettings `toml:"resolv"`
Redis RedisSettings `toml:"redis"`
Log LogSettings `toml:"log"`
Cache CacheSettings `toml:"cache"`
2013-07-26 04:06:16 +00:00
Hosts HostsSettings `toml:"hosts"`
2013-07-23 11:10:38 +00:00
}
type ResolvSettings struct {
ResolvFile string `toml:"resolv-file"`
Timeout int
}
type DNSServerSettings struct {
Host string
Port int
}
type RedisSettings struct {
Host string
Port int
DB int
Password string
}
2013-07-26 10:54:19 +00:00
func (s RedisSettings) Addr() string {
return s.Host + ":" + strconv.Itoa(s.Port)
}
2013-07-23 11:10:38 +00:00
type LogSettings struct {
File string
}
type CacheSettings struct {
Backend string
2013-07-24 16:09:07 +00:00
Expire int
2013-07-24 10:29:38 +00:00
Maxcount int
2013-07-23 11:10:38 +00:00
}
2013-07-26 04:06:16 +00:00
type HostsSettings struct {
2015-02-03 15:03:47 +00:00
Enable bool
HostsFile string `toml:"host-file"`
RedisEnable bool `toml:"redis-enable"`
RedisKey string `toml:"redis-key"`
TTL uint32 `toml:"ttl"`
2013-07-26 04:06:16 +00:00
}
2013-07-23 11:10:38 +00:00
func init() {
var configFile string
flag.StringVar(&configFile, "c", "godns.conf", "Look for godns toml-formatting config file in this directory")
flag.Parse()
if _, err := toml.DecodeFile(configFile, &settings); err != nil {
fmt.Printf("%s is not a valid toml config file\n", configFile)
fmt.Println(err)
os.Exit(1)
}
}