Torben Nehmer
467a89c4ba
- Default DNS at localhost - updated gitignore - updated default config yml
47 lines
749 B
Go
47 lines
749 B
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type config struct {
|
|
DNS configDNS
|
|
Users configUsers
|
|
}
|
|
|
|
type configDNS struct {
|
|
Server string
|
|
DefaultTTL uint32
|
|
}
|
|
|
|
type configUsers struct {
|
|
ConfigDir string
|
|
}
|
|
|
|
var C config
|
|
|
|
func init() {
|
|
SetConfigDefaults()
|
|
}
|
|
|
|
func SetConfigDefaults() {
|
|
viper.SetDefault("Service.DNS.Server", "127.0.0.1:53")
|
|
viper.SetDefault("Service.DNS.DefaultTTL", 60)
|
|
viper.SetDefault("Service.Users.ConfigDir", "users/")
|
|
}
|
|
|
|
func LoadConfig() {
|
|
viper.UnmarshalKey("Service", &C)
|
|
}
|
|
|
|
func (obj *config) PrettyPrint() string {
|
|
s, err := json.MarshalIndent(obj, "", " ")
|
|
if err != nil {
|
|
log.Fatalf("Failed to pretty print Service Config via JSON: %v", err)
|
|
}
|
|
return string(s)
|
|
}
|