mirror of
https://github.com/spf13/viper
synced 2025-05-10 22:27:18 +00:00
Implement remote watch register.
This commit is contained in:
parent
c5284b5b3e
commit
e8a67492a6
2 changed files with 5 additions and 2 deletions
|
@ -5,7 +5,7 @@ type RegisteredConfig struct {
|
||||||
CanBeNil bool
|
CanBeNil bool
|
||||||
OnUpdate func(e *Event)
|
OnUpdate func(e *Event)
|
||||||
OnUpdateFailed func(e *Event)
|
OnUpdateFailed func(e *Event)
|
||||||
Schema *interface{}
|
Schema interface{}
|
||||||
Validator func(interface{}) bool
|
Validator func(interface{}) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
viper.go
5
viper.go
|
@ -245,6 +245,7 @@ func New() *Viper {
|
||||||
v.aliases = make(map[string]string)
|
v.aliases = make(map[string]string)
|
||||||
v.typeByDefValue = false
|
v.typeByDefValue = false
|
||||||
v.logger = jwwLogger{}
|
v.logger = jwwLogger{}
|
||||||
|
v.registered = make(map[string]RegisteredConfig)
|
||||||
|
|
||||||
v.resetEncoding()
|
v.resetEncoding()
|
||||||
|
|
||||||
|
@ -1997,8 +1998,10 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
||||||
go func(rc <-chan *RemoteResponse) {
|
go func(rc <-chan *RemoteResponse) {
|
||||||
for {
|
for {
|
||||||
b := <-rc
|
b := <-rc
|
||||||
|
tempViper := New()
|
||||||
reader := bytes.NewReader(b.Value)
|
reader := bytes.NewReader(b.Value)
|
||||||
v.unmarshalReader(reader, v.kvstore)
|
tempViper.unmarshalReader(reader, tempViper.kvstore)
|
||||||
|
v.updateRegisteredConfig(tempViper)
|
||||||
}
|
}
|
||||||
}(respc)
|
}(respc)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue