Only save config on success in ReadInConfig

If the user creates a invalid config file while watching for config
changes, the previous, valid config is not retained.  This commit only
overwrites the running config if unmarshalling was successful.
This commit is contained in:
Cameron Moore 2016-12-27 21:49:59 -06:00 committed by Bjørn Erik Pedersen
parent 5ed0fc31f7
commit d90f2bb139

View file

@ -1093,9 +1093,15 @@ func (v *Viper) ReadInConfig() error {
return err
}
v.config = make(map[string]interface{})
config := make(map[string]interface{})
return v.unmarshalReader(bytes.NewReader(file), v.config)
err = v.unmarshalReader(bytes.NewReader(file), config)
if err != nil {
return err
}
v.config = config
return nil
}
// MergeInConfig merges a new configuration with an existing config.