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

@ -8,7 +8,8 @@ import (
const (
DefaultPage = 1
MinPageSize = 10
MinPageSize = 1
DefaultPageSize = 10
MaxPageSize = 1000
)
@ -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
}

@ -4,7 +4,8 @@ package page
const (
DefaultFrontPage = 1
MinFrontPageSize = 10
DefaultFrontPageSize = 10
MinFrontPageSize = 1
MaxFrontPageSize = 100
)
@ -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