diff --git a/pagination/v1/pagination.go b/pagination/v1/pagination.go index dbeee2c..c503a3b 100644 --- a/pagination/v1/pagination.go +++ b/pagination/v1/pagination.go @@ -4,6 +4,8 @@ import ( "math" ) +// 服务端用 + const ( DefaultPage = 1 MinPageSize = 10 diff --git a/pagination/v1/pagination_front.go b/pagination/v1/pagination_front.go new file mode 100644 index 0000000..31a45fa --- /dev/null +++ b/pagination/v1/pagination_front.go @@ -0,0 +1,32 @@ +package page + +// 服务端用 + +const ( + DefaultFrontPage = 1 + MinFrontPageSize = 10 + 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 <= MinFrontPageSize { + frontPerPage = MinFrontPageSize + } + + if frontPerPage >= MaxFrontPageSize { + frontPerPage = MaxPageSize + } + page = frontPage + pageSize = frontPerPage + return +}