This commit is contained in:
Raven 2019-11-09 21:16:02 -06:00 committed by GitHub
commit c65226d006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -200,11 +200,12 @@ type Viper struct {
aliases map[string]string aliases map[string]string
typeByDefValue bool typeByDefValue bool
onConfigChange func(fsnotify.Event)
onRemoteConfigChange func()
// Store read properties on the object so that we can write back in order with comments. // Store read properties on the object so that we can write back in order with comments.
// This will only be used if the configuration read is a properties file. // This will only be used if the configuration read is a properties file.
properties *properties.Properties properties *properties.Properties
onConfigChange func(fsnotify.Event)
} }
// New returns an initialized Viper instance. // New returns an initialized Viper instance.
@ -280,6 +281,11 @@ func (v *Viper) OnConfigChange(run func(in fsnotify.Event)) {
v.onConfigChange = run v.onConfigChange = run
} }
func OnRemoteConfigChange(run func()) { v.OnRemoteConfigChange(run) }
func (v *Viper) OnRemoteConfigChange(run func()) {
v.onRemoteConfigChange = run
}
func WatchConfig() { v.WatchConfig() } func WatchConfig() { v.WatchConfig() }
func (v *Viper) WatchConfig() { func (v *Viper) WatchConfig() {
@ -1639,6 +1645,7 @@ func (v *Viper) WatchRemoteConfig() error {
return v.watchKeyValueConfig() return v.watchKeyValueConfig()
} }
func WatchRemoteConfigOnChannel() error { return v.watchKeyValueConfigOnChannel() }
func (v *Viper) WatchRemoteConfigOnChannel() error { func (v *Viper) WatchRemoteConfigOnChannel() error {
return v.watchKeyValueConfigOnChannel() return v.watchKeyValueConfigOnChannel()
} }
@ -1674,13 +1681,14 @@ func (v *Viper) watchKeyValueConfigOnChannel() 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
go func(rc <-chan *RemoteResponse) {
for { b := <-respc
b := <-rc reader := bytes.NewReader(b.Value)
reader := bytes.NewReader(b.Value) v.unmarshalReader(reader, v.kvstore)
v.unmarshalReader(reader, v.kvstore)
} if v.onRemoteConfigChange != nil {
}(respc) v.onRemoteConfigChange()
}
return nil return nil
} }
return RemoteConfigError("No Files Found") return RemoteConfigError("No Files Found")