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
395c6b780d
commit
027007221d
1 changed files with 21 additions and 13 deletions
34
viper.go
34
viper.go
|
@ -527,24 +527,32 @@ func (v *Viper) updateRegisteredConfig(newConfig map[string]interface{}) (result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type check & convert
|
// Type check & convert
|
||||||
newValueJson, _ := js.Marshal(newValue)
|
if config.Schema != nil {
|
||||||
err := js.Unmarshal(newValueJson, config.Schema)
|
newValueJson, _ := js.Marshal(newValue)
|
||||||
if err != nil {
|
err := js.Unmarshal(newValueJson, config.Schema)
|
||||||
newConfig[key] = oldValue
|
if err != nil {
|
||||||
config.OnUpdateFailed(&Event{
|
newConfig[key] = oldValue
|
||||||
old: oldValue,
|
if config.OnUpdateFailed != nil {
|
||||||
new: nil,
|
config.OnUpdateFailed(&Event{
|
||||||
})
|
old: oldValue,
|
||||||
continue
|
new: nil,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config.Schema = newValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
if config.Validator != nil && !config.Validator(config.Schema) {
|
if config.Validator != nil && !config.Validator(config.Schema) {
|
||||||
newConfig[key] = oldValue
|
newConfig[key] = oldValue
|
||||||
config.OnUpdateFailed(&Event{
|
if config.OnUpdateFailed != nil {
|
||||||
old: oldValue,
|
config.OnUpdateFailed(&Event{
|
||||||
new: nil,
|
old: oldValue,
|
||||||
})
|
new: nil,
|
||||||
|
})
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue