mirror of https://github.com/spf13/viper.git
WatchRemoteConfigOnChannel
This commit is contained in:
parent
4dddf7c62e
commit
18f781b94a
16
viper.go
16
viper.go
|
@ -163,6 +163,7 @@ type Viper struct {
|
|||
typeByDefValue bool
|
||||
|
||||
onConfigChange func(fsnotify.Event)
|
||||
onRemoteConfigChange func()
|
||||
}
|
||||
|
||||
// New returns an initialized Viper instance.
|
||||
|
@ -237,6 +238,11 @@ func (v *Viper) OnConfigChange(run func(in fsnotify.Event)) {
|
|||
v.onConfigChange = run
|
||||
}
|
||||
|
||||
func OnRemoteConfigChange(run func()) { v.OnRemoteConfigChange(run) }
|
||||
func (v *Viper) OnRemoteConfigChange(run func()) {
|
||||
v.onRemoteConfigChange = run
|
||||
}
|
||||
|
||||
func WatchConfig() { v.WatchConfig() }
|
||||
func (v *Viper) WatchConfig() {
|
||||
go func() {
|
||||
|
@ -1286,6 +1292,7 @@ func (v *Viper) WatchRemoteConfig() error {
|
|||
return v.watchKeyValueConfig()
|
||||
}
|
||||
|
||||
func WatchRemoteConfigOnChannel() error { return v.watchKeyValueConfigOnChannel() }
|
||||
func (v *Viper) WatchRemoteConfigOnChannel() error {
|
||||
return v.watchKeyValueConfigOnChannel()
|
||||
}
|
||||
|
@ -1338,13 +1345,14 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
|||
for _, rp := range v.remoteProviders {
|
||||
respc, _ := RemoteConfig.WatchChannel(rp)
|
||||
//Todo: Add quit channel
|
||||
go func(rc <-chan *RemoteResponse) {
|
||||
for {
|
||||
b := <-rc
|
||||
|
||||
b := <-respc
|
||||
reader := bytes.NewReader(b.Value)
|
||||
v.unmarshalReader(reader, v.kvstore)
|
||||
|
||||
if v.onRemoteConfigChange != nil {
|
||||
v.onRemoteConfigChange()
|
||||
}
|
||||
}(respc)
|
||||
return nil
|
||||
}
|
||||
return RemoteConfigError("No Files Found")
|
||||
|
|
Loading…
Reference in New Issue