dyndns/service/config.go
Torben Nehmer 7b93ff425d - Added sample default config (needs manual updating)
- Reworked service and webapi config to Viper unmarshalling
- Added Pretty Printers to config
2021-08-22 14:46:48 +02:00

47 lines
752 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", "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)
}