Implement remote watch register.

This commit is contained in:
cyprinus 2023-06-04 11:13:23 +08:00
parent c5284b5b3e
commit e8a67492a6
2 changed files with 5 additions and 2 deletions

View file

@ -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
} }

View file

@ -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