From 1e2868c77cbb9a1fc2328f532d9da384bf46f277 Mon Sep 17 00:00:00 2001 From: nikkiing <1031497516@qq.com> Date: Fri, 21 Apr 2023 14:17:46 +0800 Subject: [PATCH] FrontToBackend --- pagination/v1/pagination.go | 2 ++ pagination/v1/pagination_front.go | 32 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 pagination/v1/pagination_front.go 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 +}