mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57:18 +00:00
Merge d18964fe22
into 01d7d76eb0
This commit is contained in:
commit
c65226d006
1 changed files with 17 additions and 9 deletions
26
viper.go
26
viper.go
|
@ -200,11 +200,12 @@ type Viper struct {
|
|||
aliases map[string]string
|
||||
typeByDefValue bool
|
||||
|
||||
onConfigChange func(fsnotify.Event)
|
||||
onRemoteConfigChange func()
|
||||
|
||||
// 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.
|
||||
properties *properties.Properties
|
||||
|
||||
onConfigChange func(fsnotify.Event)
|
||||
}
|
||||
|
||||
// New returns an initialized Viper instance.
|
||||
|
@ -280,6 +281,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() {
|
||||
|
@ -1639,6 +1645,7 @@ func (v *Viper) WatchRemoteConfig() error {
|
|||
return v.watchKeyValueConfig()
|
||||
}
|
||||
|
||||
func WatchRemoteConfigOnChannel() error { return v.watchKeyValueConfigOnChannel() }
|
||||
func (v *Viper) WatchRemoteConfigOnChannel() error {
|
||||
return v.watchKeyValueConfigOnChannel()
|
||||
}
|
||||
|
@ -1674,13 +1681,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
|
||||
reader := bytes.NewReader(b.Value)
|
||||
v.unmarshalReader(reader, v.kvstore)
|
||||
}
|
||||
}(respc)
|
||||
|
||||
b := <-respc
|
||||
reader := bytes.NewReader(b.Value)
|
||||
v.unmarshalReader(reader, v.kvstore)
|
||||
|
||||
if v.onRemoteConfigChange != nil {
|
||||
v.onRemoteConfigChange()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return RemoteConfigError("No Files Found")
|
||||
|
|
Loading…
Add table
Reference in a new issue