mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57: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
|
||||
newValueJson, _ := js.Marshal(newValue)
|
||||
err := js.Unmarshal(newValueJson, config.Schema)
|
||||
if err != nil {
|
||||
newConfig[key] = oldValue
|
||||
config.OnUpdateFailed(&Event{
|
||||
old: oldValue,
|
||||
new: nil,
|
||||
})
|
||||
continue
|
||||
if config.Schema != nil {
|
||||
newValueJson, _ := js.Marshal(newValue)
|
||||
err := js.Unmarshal(newValueJson, config.Schema)
|
||||
if err != nil {
|
||||
newConfig[key] = oldValue
|
||||
if config.OnUpdateFailed != nil {
|
||||
config.OnUpdateFailed(&Event{
|
||||
old: oldValue,
|
||||
new: nil,
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
config.Schema = newValue
|
||||
}
|
||||
|
||||
// Validation
|
||||
if config.Validator != nil && !config.Validator(config.Schema) {
|
||||
newConfig[key] = oldValue
|
||||
config.OnUpdateFailed(&Event{
|
||||
old: oldValue,
|
||||
new: nil,
|
||||
})
|
||||
if config.OnUpdateFailed != nil {
|
||||
config.OnUpdateFailed(&Event{
|
||||
old: oldValue,
|
||||
new: nil,
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue