godns/settings.go

66 lines
1.1 KiB
Go
Raw Normal View History

2013-07-23 11:10:38 +00:00
package main
import (
"flag"
"fmt"
"github.com/BurntSushi/toml"
"os"
"time"
)
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"`
}
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
}
type LogSettings struct {
File string
}
type CacheSettings struct {
Backend string
Expire time.Duration
2013-07-24 10:29:38 +00:00
Maxcount int
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)
}
}