fix: ensure proper handling of JSON unmarshalling for maps in config update

This commit is contained in:
CaIon
2026-04-27 22:07:46 +08:00
parent e36d191c2e
commit 4e93148d9e
2 changed files with 106 additions and 2 deletions
+10 -2
View File
@@ -252,8 +252,16 @@ func updateConfigFromMap(config interface{}, configMap map[string]string) error
continue
}
}
case reflect.Map, reflect.Slice, reflect.Struct:
// 复杂类型使用JSON反序列化
case reflect.Map:
// json.Unmarshal merges into existing maps (keeps old keys that are
// absent from the new JSON). Allocate a fresh map so removed keys
// are properly cleared.
fresh := reflect.New(field.Type())
if err := json.Unmarshal([]byte(strValue), fresh.Interface()); err != nil {
continue
}
field.Set(fresh.Elem())
case reflect.Slice, reflect.Struct:
err := json.Unmarshal([]byte(strValue), field.Addr().Interface())
if err != nil {
continue