mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-09 05:36:27 +08:00
<!--
## 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>
27 lines
791 B
Go
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
|
|
}
|