改bug
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
// Package models 定义了应用的数据模型,例如用户、产品等。
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -15,6 +18,24 @@ type ContactInfo struct {
|
||||
Feishu string `json:"feishu,omitempty"`
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner 接口,用于从数据库读取 JSONB 数据
|
||||
func (ci *ContactInfo) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
*ci = ContactInfo{} // 如果数据库值为 NULL,则初始化为空结构体
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return errors.New("type assertion to []byte failed for ContactInfo")
|
||||
}
|
||||
return json.Unmarshal(bytes, ci)
|
||||
}
|
||||
|
||||
// Value 实现 driver.Valuer 接口,用于将 ContactInfo 写入数据库为 JSONB 数据
|
||||
func (ci ContactInfo) Value() (driver.Value, error) {
|
||||
return json.Marshal(ci)
|
||||
}
|
||||
|
||||
// User 代表系统中的用户模型
|
||||
type User struct {
|
||||
// gorm.Model 内嵌了 ID, CreatedAt, UpdatedAt, 和 DeletedAt
|
||||
|
||||
Reference in New Issue
Block a user