mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57: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
|
||||
OnUpdate func(e *Event)
|
||||
OnUpdateFailed func(e *Event)
|
||||
Schema *interface{}
|
||||
Schema interface{}
|
||||
Validator func(interface{}) bool
|
||||
}
|
||||
|
||||
|
|
5
viper.go
5
viper.go
|
@ -245,6 +245,7 @@ func New() *Viper {
|
|||
v.aliases = make(map[string]string)
|
||||
v.typeByDefValue = false
|
||||
v.logger = jwwLogger{}
|
||||
v.registered = make(map[string]RegisteredConfig)
|
||||
|
||||
v.resetEncoding()
|
||||
|
||||
|
@ -1997,8 +1998,10 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
|||
go func(rc <-chan *RemoteResponse) {
|
||||
for {
|
||||
b := <-rc
|
||||
tempViper := New()
|
||||
reader := bytes.NewReader(b.Value)
|
||||
v.unmarshalReader(reader, v.kvstore)
|
||||
tempViper.unmarshalReader(reader, tempViper.kvstore)
|
||||
v.updateRegisteredConfig(tempViper)
|
||||
}
|
||||
}(respc)
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue