refactor(model): support string type in JSON scan methods
All checks were successful
Build Backend / build (push) Successful in 5m57s
Build Backend / build-docker (push) Successful in 1m16s

Enhance Scan methods in StringArray, ExtraData, MessageSegments, and
SystemNotificationExtra to accept both []byte and string types from database.
Uses type switch for more flexible type handling.
This commit is contained in:
lafay
2026-04-24 15:58:28 +08:00
parent 813e54e5b2
commit 496c8bb1aa
3 changed files with 35 additions and 15 deletions

View File

@@ -71,11 +71,16 @@ func (a *StringArray) Scan(value any) error {
*a = nil
return nil
}
bytes, ok := value.([]byte)
if !ok {
var data []byte
switch v := value.(type) {
case []byte:
data = v
case string:
data = []byte(v)
default:
return nil
}
return json.Unmarshal(bytes, a)
return json.Unmarshal(data, a)
}
// MaterialFile 文件资料