From 2a7f06060dd94ce615af6d1e70e1f6d73caff8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 14 Oct 2023 21:47:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8Epage=20+=20size?= =?UTF-8?q?=E6=9E=84=E5=BB=BAlimit/offset=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- option.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/option.go b/option.go index a8fe2a6..170954b 100644 --- a/option.go +++ b/option.go @@ -88,6 +88,23 @@ func WithLimit[T op_type.Int](limit T, offset T) SetOption { } } +// WithLimitByPageAndSize 通过page和size构建条件 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:42 2023/10/14 +func WithLimitByPageAndSize[T op_type.Int](page T, size T) SetOption { + return func(o *Option) { + if size > 0 { + o.Limit = int(size) + } + if page <= 0 { + page = 1 + } + o.Offset = int((page - 1) * size) + } +} + // WithIn 设置in条件 // // Author : go_developer@163.com<白茶清欢>