dyndns/service/config.go

47 lines
752 B
Go
Raw Normal View History

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", "10.10.11.254: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)
}