mirror of
https://github.com/spf13/viper
synced 2025-05-10 22:27:18 +00:00
Fix watch register.
This commit is contained in:
parent
eebc2f0d0b
commit
395c6b780d
1 changed files with 6 additions and 4 deletions
10
viper.go
10
viper.go
|
@ -508,7 +508,9 @@ func (v *Viper) WatchConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateRegisteredConfig validate the registered config items in the new config, notify user with the hook functions.
|
// updateRegisteredConfig validate the registered config items in the new config, notify user with the hook functions.
|
||||||
func (v *Viper) updateRegisteredConfig(newConfig map[string]interface{}) map[string]interface{} {
|
func (v *Viper) updateRegisteredConfig(newConfig map[string]interface{}) (result map[string]interface{}) {
|
||||||
|
result = make(map[string]interface{})
|
||||||
|
|
||||||
for key, config := range v.registered {
|
for key, config := range v.registered {
|
||||||
oldValue := v.Get(key)
|
oldValue := v.Get(key)
|
||||||
newValue := newConfig[key]
|
newValue := newConfig[key]
|
||||||
|
@ -537,7 +539,7 @@ func (v *Viper) updateRegisteredConfig(newConfig map[string]interface{}) map[str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
if !config.Validator(config.Schema) {
|
if config.Validator != nil && !config.Validator(config.Schema) {
|
||||||
newConfig[key] = oldValue
|
newConfig[key] = oldValue
|
||||||
config.OnUpdateFailed(&Event{
|
config.OnUpdateFailed(&Event{
|
||||||
old: oldValue,
|
old: oldValue,
|
||||||
|
@ -547,7 +549,7 @@ func (v *Viper) updateRegisteredConfig(newConfig map[string]interface{}) map[str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
newConfig[key] = config.Schema
|
result[key] = config.Schema
|
||||||
if config.OnUpdate != nil {
|
if config.OnUpdate != nil {
|
||||||
config.OnUpdate(&Event{
|
config.OnUpdate(&Event{
|
||||||
new: config.Schema,
|
new: config.Schema,
|
||||||
|
@ -555,7 +557,7 @@ func (v *Viper) updateRegisteredConfig(newConfig map[string]interface{}) map[str
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newConfig
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConfigFile explicitly defines the path, name and extension of the config file.
|
// SetConfigFile explicitly defines the path, name and extension of the config file.
|
||||||
|
|
Loading…
Add table
Reference in a new issue