Fix: viper.UnmarshalKey ignores defaults

This seems to be a bug in viper, as soon as we're working with subkeys, things fall apart
This commit is contained in:
Torben Nehmer 2021-08-24 17:03:59 +02:00
parent 467a89c4ba
commit a6e52d9d3d
2 changed files with 12 additions and 2 deletions

View File

@ -34,7 +34,13 @@ func SetConfigDefaults() {
} }
func LoadConfig() { func LoadConfig() {
viper.UnmarshalKey("Service", &C) // Does not work with partially overrides, only GetXXX does resolve the subkeys correctly
// https://github.com/spf13/viper/issues/798
// https://github.com/spf13/viper/issues/309
// viper.UnmarshalKey("Service", &C)
C.DNS.Server = viper.GetString("Service.DNS.Server")
C.DNS.DefaultTTL = viper.GetUint32("Service.DNS.DefaultTTL")
C.Users.ConfigDir = viper.GetString("Service.Users.ConfigDir")
} }
func (obj *config) PrettyPrint() string { func (obj *config) PrettyPrint() string {

View File

@ -22,7 +22,11 @@ func SetConfigDefaults() {
} }
func LoadConfig() { func LoadConfig() {
viper.UnmarshalKey("WebAPI", &C) // Does not work with partially overrides, only GetXXX does resolve the subkeys correctly
// https://github.com/spf13/viper/issues/798
// https://github.com/spf13/viper/issues/309
// viper.UnmarshalKey("WebAPI", &C)
C.ListenAddress = viper.GetString("WebAPI.ListenAddress")
} }
func (obj *config) PrettyPrint() string { func (obj *config) PrettyPrint() string {