通用包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
utils/pagination/v1/pagination_front.go

38 lines
685 B

2 years ago
package page
// 服务端用
const (
1 year ago
DefaultFrontPage = 1
DefaultFrontPageSize = 10
MinFrontPageSize = 1
MaxFrontPageSize = 100
2 years ago
)
type PaginationFront struct {
Page int32 `json:"page"`
PerPage int32 `json:"per_page"`
Total int32 `json:"total"`
}
func FrontToBackend[T Integer](frontPage, frontPerPage T) (page, pageSize T) {
if frontPage < DefaultFrontPage {
frontPage = DefaultPage
}
1 year ago
if frontPerPage <= 0 {
frontPerPage = DefaultFrontPageSize
}
2 years ago
if frontPerPage <= MinFrontPageSize {
frontPerPage = MinFrontPageSize
}
if frontPerPage >= MaxFrontPageSize {
frontPerPage = MaxPageSize
}
page = frontPage
pageSize = frontPerPage
return
}