mirror of
https://github.com/spf13/viper
synced 2024-11-20 03:47:05 +00:00
fix: unmarshalReader to an empty kvstore, just as ReadConfig. for example, avoid kvstore not changed if read an empty yaml
This commit is contained in:
parent
f1d2c470bf
commit
f55aacba8a
1 changed files with 21 additions and 5 deletions
26
viper.go
26
viper.go
|
@ -1903,8 +1903,13 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{}
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = v.unmarshalReader(reader, v.kvstore)
|
||||
return v.kvstore, err
|
||||
kvstore := make(map[string]interface{})
|
||||
err = v.unmarshalReader(reader, kvstore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.kvstore = kvstore
|
||||
return v.kvstore, nil
|
||||
}
|
||||
|
||||
// Retrieve the first found remote configuration.
|
||||
|
@ -1920,7 +1925,13 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
|||
for {
|
||||
b := <-rc
|
||||
reader := bytes.NewReader(b.Value)
|
||||
v.unmarshalReader(reader, v.kvstore)
|
||||
kvstore := make(map[string]interface{})
|
||||
err := v.unmarshalReader(reader, kvstore)
|
||||
if err != nil {
|
||||
v.logger.Warn(fmt.Errorf("watch remote config: %w", err).Error())
|
||||
continue
|
||||
}
|
||||
v.kvstore = kvstore
|
||||
}
|
||||
}(respc)
|
||||
return nil
|
||||
|
@ -1952,8 +1963,13 @@ func (v *Viper) watchRemoteConfig(provider RemoteProvider) (map[string]interface
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = v.unmarshalReader(reader, v.kvstore)
|
||||
return v.kvstore, err
|
||||
kvstore := make(map[string]interface{})
|
||||
err = v.unmarshalReader(reader, kvstore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.kvstore = kvstore
|
||||
return v.kvstore, nil
|
||||
}
|
||||
|
||||
// AllKeys returns all keys holding a value, regardless of where they are set.
|
||||
|
|
Loading…
Reference in a new issue