From 7ba3455b8844e2837387ec9ffc28426e0bae06fd Mon Sep 17 00:00:00 2001 From: wangxin Date: Thu, 18 Nov 2021 18:57:23 +0800 Subject: [PATCH] feat(remote): add callback when remote channel changes --- viper.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/viper.go b/viper.go index 6c456a9..21a35b2 100644 --- a/viper.go +++ b/viper.go @@ -1859,8 +1859,8 @@ func (v *Viper) WatchRemoteConfig() error { return v.watchKeyValueConfig() } -func (v *Viper) WatchRemoteConfigOnChannel() error { - return v.watchKeyValueConfigOnChannel() +func (v *Viper) WatchRemoteConfigOnChannel(run func()) error { + return v.watchKeyValueConfigOnChannel(run) } // 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. -func (v *Viper) watchKeyValueConfigOnChannel() error { +func (v *Viper) watchKeyValueConfigOnChannel(run func()) error { for _, rp := range v.remoteProviders { respc, _ := RemoteConfig.WatchChannel(rp) // Todo: Add quit channel @@ -1903,6 +1903,7 @@ func (v *Viper) watchKeyValueConfigOnChannel() error { b := <-rc reader := bytes.NewReader(b.Value) v.unmarshalReader(reader, v.kvstore) + run() } }(respc) return nil