58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"errors"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Model 基础模型
|
|
type Model struct {
|
|
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"`
|
|
PageSize int `json:"pageSize" form:"pageSize"`
|
|
Keyword string `json:"keyword" form:"keyword"`
|
|
}
|
|
|
|
// PageResult 分页响应
|
|
type PageResult struct {
|
|
List interface{} `json:"list"`
|
|
Total int64 `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|