mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = v.unmarshalReader(reader, v.kvstore)
|
kvstore := make(map[string]interface{})
|
||||||
return v.kvstore, err
|
err = v.unmarshalReader(reader, kvstore)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
v.kvstore = kvstore
|
||||||
|
return v.kvstore, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the first found remote configuration.
|
// Retrieve the first found remote configuration.
|
||||||
|
@ -1920,7 +1925,13 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
||||||
for {
|
for {
|
||||||
b := <-rc
|
b := <-rc
|
||||||
reader := bytes.NewReader(b.Value)
|
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)
|
}(respc)
|
||||||
return nil
|
return nil
|
||||||
|
@ -1952,8 +1963,13 @@ func (v *Viper) watchRemoteConfig(provider RemoteProvider) (map[string]interface
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = v.unmarshalReader(reader, v.kvstore)
|
kvstore := make(map[string]interface{})
|
||||||
return v.kvstore, err
|
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.
|
// AllKeys returns all keys holding a value, regardless of where they are set.
|
||||||
|
|
Loading…
Reference in a new issue