dyndns/webapi/config.go

35 lines
512 B
Go
Raw Normal View History

package webapi
import (
"encoding/json"
"log"
"github.com/spf13/viper"
)
type config struct {
ListenAddress string
}
var C config
func init() {
SetConfigDefaults()
}
func SetConfigDefaults() {
viper.SetDefault("WebAPI.ListenAddress", ":8080")
}
func LoadConfig() {
viper.UnmarshalKey("WebAPI", &C)
}
func (obj *config) PrettyPrint() string {
s, err := json.MarshalIndent(obj, "", " ")
if err != nil {
log.Fatalf("Failed to pretty print WebAPI Config via JSON: %v", err)
}
return string(s)
}