feat(client): detect pagination limit at client instantiation

Closes #15
This commit is contained in:
Julien Dessaux 2025-05-25 18:12:46 +02:00
parent f4d69460af
commit 7e1e9eb26b
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 25 additions and 15 deletions

View file

@ -41,7 +41,7 @@ func (c *Client) UsersList(ctx context.Context) ([]User, error) {
}
uriRef := url.URL{Path: "api/v1/users/search"}
query := make(url.Values)
query.Set("limit", maxItemsPerPageStr)
query.Set("limit", c.maxItemsPerPageStr)
page := 1
var users []User
var response Response
@ -56,7 +56,7 @@ func (c *Client) UsersList(ctx context.Context) ([]User, error) {
return nil, fmt.Errorf("got a non OK status when searching users")
}
users = append(users, response.Data...)
if count <= page*maxItemsPerPage {
if count <= page*c.maxItemsPerPage {
return users, nil
}
page++