dnscontrol/providers/alidns/pagination.go
Jiacheng bcef7f52fc
ALIDNS: Implement ALIDNS Provider (#3878)
<!--
## Before submiting a pull request

Please make sure you've run the following commands from the root
directory.

    bin/generate-all.sh

(this runs commands like "go generate", fixes formatting, and so on)

## Release changelog section

Help keep the release changelog clear by pre-naming the proper section
in the GitHub pull request title.

Some examples:
* CICD: Add required GHA permissions for goreleaser
* DOCS: Fixed providers with "contributor support" table
* ROUTE53: Allow R53_ALIAS records to enable target health evaluation

More examples/context can be found in the file .goreleaser.yml under the
'build' > 'changelog' key.
!-->

https://github.com/StackExchange/dnscontrol/issues/420


Please create the GitHub label 'provider-ALIDNS'

---------

Co-authored-by: Tom Limoncelli <6293917+tlimoncelli@users.noreply.github.com>
2025-12-04 10:55:14 -05:00

27 lines
791 B
Go

package alidns
// paginateAll is a small generic paginator helper. The caller provides a
// fetch function that requests a single page (pageNumber,pageSize) and
// returns the items for that page, the total number of items available,
// and an error if any. paginateAll will iterate pages until it has
// collected all items or an error occurs.
func paginateAll[T any](fetch func(pageNumber, pageSize int) ([]T, int, error), maxPageSize int) ([]T, error) {
page := 1
pageSize := maxPageSize
var out []T
for {
items, total, err := fetch(page, pageSize)
if err != nil {
return nil, err
}
out = append(out, items...)
// If we've collected all items, or the page returned nothing, stop.
if len(out) >= total || len(items) == 0 {
break
}
page++
}
return out, nil
}