2021-08-15 19:37:11 +00:00
|
|
|
package service
|
|
|
|
|
2021-08-22 12:46:48 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
2021-08-15 19:37:11 +00:00
|
|
|
|
|
|
|
type config struct {
|
2021-08-22 12:46:48 +00:00
|
|
|
DNS configDNS
|
|
|
|
Users configUsers
|
|
|
|
}
|
|
|
|
|
|
|
|
type configDNS struct {
|
|
|
|
Server string
|
|
|
|
DefaultTTL uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type configUsers struct {
|
|
|
|
ConfigDir string
|
2021-08-15 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var C config
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
SetConfigDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetConfigDefaults() {
|
|
|
|
viper.SetDefault("Service.DNS.Server", "10.10.11.254:53")
|
|
|
|
viper.SetDefault("Service.DNS.DefaultTTL", 60)
|
2021-08-21 18:34:45 +00:00
|
|
|
viper.SetDefault("Service.Users.ConfigDir", "users/")
|
2021-08-15 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig() {
|
2021-08-22 12:46:48 +00:00
|
|
|
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)
|
2021-08-15 19:37:11 +00:00
|
|
|
}
|