From 223f0a75e02d6c7545f80f588436f950d270b58d Mon Sep 17 00:00:00 2001 From: Norwin Date: Wed, 27 Apr 2022 03:07:37 +0800 Subject: [PATCH] ListOptions.setDefaults(): remove artificial and buggy pagination limits (#573) fixes #571 Co-authored-by: Norwin Co-authored-by: Andrew Thornton Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/573 Reviewed-by: Gusted Reviewed-by: Andrew Thornton Co-authored-by: Norwin Co-committed-by: Norwin --- gitea/list_options.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/gitea/list_options.go b/gitea/list_options.go index 6f3ffb2..fb1aff4 100644 --- a/gitea/list_options.go +++ b/gitea/list_options.go @@ -9,12 +9,13 @@ import ( "net/url" ) -const defaultPageSize = 10 -const maxPageSize = 50 - // ListOptions options for using Gitea's API pagination type ListOptions struct { - Page int + // Setting Page to -1 disables pagination on endpoints that support it. + // Page numbering starts at 1. + Page int + // The default value depends on the server config DEFAULT_PAGING_NUM + // The highest valid value depends on the server config MAX_RESPONSE_ITEMS PageSize int } @@ -26,8 +27,9 @@ func (o ListOptions) getURLQuery() url.Values { return query } -// setDefaults set default pagination options if none or wrong are set -// if you set -1 as page it will set all to 0 +// setDefaults applies default pagination options. +// If .Page is set to -1, it will disable pagination. +// WARNING: This function is not idempotent, make sure to never call this method twice! func (o *ListOptions) setDefaults() { if o.Page < 0 { o.Page, o.PageSize = 0, 0 @@ -35,8 +37,4 @@ func (o *ListOptions) setDefaults() { } else if o.Page == 0 { o.Page = 1 } - - if o.PageSize < 0 || o.PageSize > maxPageSize { - o.PageSize = defaultPageSize - } }