任务三

This commit is contained in:
Yvan
2026-01-07 11:39:23 +08:00
parent b63a296144
commit 259f91c549
64 changed files with 14396 additions and 26 deletions
+28 -1
View File
@@ -1,6 +1,9 @@
package model
import (
"database/sql/driver"
"encoding/json"
"errors"
"time"
"gorm.io/gorm"
@@ -8,12 +11,36 @@ import (
// Model 基础模型
type Model struct {
ID uint `gorm:"primarykey" json:"id"`
ID uint `gorm:"primarykey" json:"ID"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// JSONMap JSON Map类型
type JSONMap map[string]interface{}
// Value 实现driver.Valuer接口
func (j JSONMap) Value() (driver.Value, error) {
if j == nil {
return nil, nil
}
return json.Marshal(j)
}
// Scan 实现sql.Scanner接口
func (j *JSONMap) Scan(value interface{}) error {
if value == nil {
*j = nil
return nil
}
bytes, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(bytes, j)
}
// PageInfo 分页请求
type PageInfo struct {
Page int `json:"page" form:"page"`