通用包
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

37 lines
685 B

package page
// 服务端用
const (
DefaultFrontPage = 1
DefaultFrontPageSize = 10
MinFrontPageSize = 1
MaxFrontPageSize = 100
)
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
}
if frontPerPage <= 0 {
frontPerPage = DefaultFrontPageSize
}
if frontPerPage <= MinFrontPageSize {
frontPerPage = MinFrontPageSize
}
if frontPerPage >= MaxFrontPageSize {
frontPerPage = MaxPageSize
}
page = frontPage
pageSize = frontPerPage
return
}