Skip to content

Commit

Permalink
Merge pull request #27 from skibish/fix-pagination
Browse files Browse the repository at this point in the history
fix(do): return 200 records instead of default 20
  • Loading branch information
skibish authored Jun 3, 2021
2 parents c8aff55 + ccd188e commit 8a4b5cf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion do/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"time"

log "github.com/sirupsen/logrus"
"github.com/skibish/ddns/misc"
)

Expand All @@ -28,6 +29,11 @@ type Record struct {

type domainRecords struct {
Records []Record `json:"domain_records"`
Links struct {
Pages struct {
Next string `json:"next"`
} `json:"pages"`
} `json:"links"`
}

// DomainsService is an interface to interact with DNS records.
Expand Down Expand Up @@ -57,7 +63,7 @@ func New(token string, timeout time.Duration) *DigitalOcean {

// List return domain DNS records.
func (d *DigitalOcean) List(ctx context.Context, domain string) ([]Record, error) {
req, err := d.prepareRequest(http.MethodGet, fmt.Sprintf("/domains/%s/records", domain), nil)
req, err := d.prepareRequest(http.MethodGet, fmt.Sprintf("/domains/%s/records?per_page=200", domain), nil)
if err != nil {
return nil, fmt.Errorf("failed to prepare a request: %w", err)
}
Expand All @@ -83,6 +89,10 @@ func (d *DigitalOcean) List(ctx context.Context, domain string) ([]Record, error
return nil, fmt.Errorf("failed to decode the response: %w", err)
}

if records.Links.Pages.Next != "" {
log.Debugf("there are more than 200 dns record for %s domain, are you sure that's correct? if yes, please raise an issue here: https://github.com/skibish/ddns/issues/new", domain)
}

return records.Records, nil
}

Expand Down

0 comments on commit 8a4b5cf

Please sign in to comment.