refactor(model): support string type in JSON scan methods
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:
@@ -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 文件资料
|
||||
|
||||
Reference in New Issue
Block a user