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:
@@ -79,11 +79,16 @@ func (e *SystemNotificationExtra) Scan(value any) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return errors.New("type assertion to []byte failed")
|
||||
var data []byte
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
data = v
|
||||
case string:
|
||||
data = []byte(v)
|
||||
default:
|
||||
return errors.New("type assertion to []byte or string failed")
|
||||
}
|
||||
return json.Unmarshal(bytes, e)
|
||||
return json.Unmarshal(data, e)
|
||||
}
|
||||
|
||||
// SystemNotification 系统通知(独立表,与消息完全分离)
|
||||
|
||||
Reference in New Issue
Block a user