diff --git a/pagination/v1/pagination.go b/pagination/v1/pagination.go index c503a3b..b291fd4 100644 --- a/pagination/v1/pagination.go +++ b/pagination/v1/pagination.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 } diff --git a/pagination/v1/pagination_front.go b/pagination/v1/pagination_front.go index 31a45fa..7d24acd 100644 --- a/pagination/v1/pagination_front.go +++ b/pagination/v1/pagination_front.go @@ -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 }