diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/config/config.go | 9 | ||||
-rw-r--r-- | internal/config/state.go | 7 |
2 files changed, 5 insertions, 11 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 573f2b3a2..3a1775778 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -130,12 +130,3 @@ func (cfg *Configuration) MarshalMap() (map[string]interface{}, error) { } return dst, nil } - -// UnmarshalMap will unmarshal a map structure into the receiving Configuration. -func (cfg *Configuration) UnmarshalMap(src map[string]interface{}) error { - dec, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ - TagName: "name", - Result: cfg, - }) - return dec.Decode(src) -} diff --git a/internal/config/state.go b/internal/config/state.go index 70972a835..1364fb84e 100644 --- a/internal/config/state.go +++ b/internal/config/state.go @@ -22,6 +22,7 @@ import ( "strings" "sync" + "github.com/mitchellh/mapstructure" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -129,8 +130,10 @@ func (st *ConfigState) reloadToViper() { // reloadFromViper will reload Configuration{} values from viper. func (st *ConfigState) reloadFromViper() { - err := st.config.UnmarshalMap(st.viper.AllSettings()) - if err != nil { + if err := st.viper.Unmarshal(&st.config, func(c *mapstructure.DecoderConfig) { + c.TagName = "name" + c.ZeroFields = true // empty the config struct before we marshal values into it + }); err != nil { panic(err) } } |