mirror of
https://github.com/spf13/viper
synced 2024-11-17 02:17:02 +00:00
feat(remote): add callback when remote channel changes
This commit is contained in:
parent
793ee22246
commit
7ba3455b88
1 changed files with 4 additions and 3 deletions
7
viper.go
7
viper.go
|
@ -1859,8 +1859,8 @@ func (v *Viper) WatchRemoteConfig() error {
|
||||||
return v.watchKeyValueConfig()
|
return v.watchKeyValueConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Viper) WatchRemoteConfigOnChannel() error {
|
func (v *Viper) WatchRemoteConfigOnChannel(run func()) error {
|
||||||
return v.watchKeyValueConfigOnChannel()
|
return v.watchKeyValueConfigOnChannel(run)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the first found remote configuration.
|
// Retrieve the first found remote configuration.
|
||||||
|
@ -1894,7 +1894,7 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the first found remote configuration.
|
// Retrieve the first found remote configuration.
|
||||||
func (v *Viper) watchKeyValueConfigOnChannel() error {
|
func (v *Viper) watchKeyValueConfigOnChannel(run func()) error {
|
||||||
for _, rp := range v.remoteProviders {
|
for _, rp := range v.remoteProviders {
|
||||||
respc, _ := RemoteConfig.WatchChannel(rp)
|
respc, _ := RemoteConfig.WatchChannel(rp)
|
||||||
// Todo: Add quit channel
|
// Todo: Add quit channel
|
||||||
|
@ -1903,6 +1903,7 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
||||||
b := <-rc
|
b := <-rc
|
||||||
reader := bytes.NewReader(b.Value)
|
reader := bytes.NewReader(b.Value)
|
||||||
v.unmarshalReader(reader, v.kvstore)
|
v.unmarshalReader(reader, v.kvstore)
|
||||||
|
run()
|
||||||
}
|
}
|
||||||
}(respc)
|
}(respc)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue