master
nikkiing 1 year ago
parent 89cf3e6dc2
commit 80d23bb340
  1. 15
      pagination/v1/pagination.go
  2. 11
      pagination/v1/pagination_front.go

@ -7,9 +7,10 @@ import (
// 服务端用
const (
DefaultPage = 1
MinPageSize = 10
MaxPageSize = 1000
DefaultPage = 1
MinPageSize = 1
DefaultPageSize = 10
MaxPageSize = 1000
)
type Pagination struct {
@ -29,6 +30,10 @@ func PageToSlice[T Integer](page, pageSize, total T) (begin, end T) {
page = DefaultPage
}
if pageSize <= 0 {
pageSize = DefaultPageSize
}
if pageSize <= MinPageSize {
pageSize = MinPageSize
}
@ -58,6 +63,10 @@ func PageToOffset[T Integer](page, pageSize T) (offset, limit T) {
page = DefaultPage
}
if pageSize <= 0 {
pageSize = DefaultPageSize
}
if pageSize <= MinPageSize {
pageSize = MinPageSize
}

@ -3,9 +3,10 @@ package page
// 服务端用
const (
DefaultFrontPage = 1
MinFrontPageSize = 10
MaxFrontPageSize = 100
DefaultFrontPage = 1
DefaultFrontPageSize = 10
MinFrontPageSize = 1
MaxFrontPageSize = 100
)
type PaginationFront struct {
@ -19,6 +20,10 @@ func FrontToBackend[T Integer](frontPage, frontPerPage T) (page, pageSize T) {
frontPage = DefaultPage
}
if frontPerPage <= 0 {
frontPerPage = DefaultFrontPageSize
}
if frontPerPage <= MinFrontPageSize {
frontPerPage = MinFrontPageSize
}

Loading…
Cancel
Save