viper-app/api/require/common.go

27 lines
549 B
Go

package require
type CommonPaginationReq struct {
Page int `form:"page" json:"page" swaggerignore:"true" `
Size int `form:"size" json:"size" swaggerignore:"true" `
}
func (req CommonPaginationReq) ToParam() *PaginationParam {
p := new(PaginationParam)
p.Size = req.Size
p.Page = req.Page
return p
}
type PaginationParam struct {
CommonPaginationReq
// rsp total page_size
Total int64
}
func (p *PaginationParam) Enable() bool {
return p.Page > 0 && p.Size > 0
}
func (p *PaginationParam) Offset() int {
return (p.Page - 1) * p.Size
}