settings: Convert JSON strings to the given type

This commit is contained in:
nemunaire 2022-07-12 09:35:43 +02:00
parent 95aadffb2e
commit 8aba067d05
1 changed files with 7 additions and 0 deletions

View File

@ -110,6 +110,13 @@ func MergeSettings(current Settings, new map[string]interface{}) *Settings {
}
if v, ok := new[name]; ok {
if reflect.TypeOf(v) != reflect.ValueOf(&current).Elem().FieldByName(field.Name).Type() {
nv := reflect.New(reflect.ValueOf(&current).Elem().FieldByName(field.Name).Type())
mv, _ := json.Marshal(v)
json.Unmarshal(mv, nv.Interface())
v = nv.Elem().Interface()
}
reflect.ValueOf(&current).Elem().FieldByName(field.Name).Set(reflect.ValueOf(v))
}
}