26 lines
524 B
Go
26 lines
524 B
Go
package model
|
|
|
|
import "time"
|
|
|
|
type Pagination struct {
|
|
Page int `form:"page" binding:"omitempty,min=1"`
|
|
PageSize int `form:"page_size" binding:"omitempty,min=1,max=100"`
|
|
}
|
|
|
|
func (p *Pagination) Normalize() {
|
|
if p.Page <= 0 {
|
|
p.Page = 1
|
|
}
|
|
if p.PageSize <= 0 {
|
|
p.PageSize = 10
|
|
}
|
|
}
|
|
|
|
func (p Pagination) Offset() int { return (p.Page - 1) * p.PageSize }
|
|
|
|
type BaseModel struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|