From ccd188e0e6d868d7a17ccba7a402162a0a502102 Mon Sep 17 00:00:00 2001 From: Sergey Kibish Date: Thu, 3 Jun 2021 18:59:26 +0300 Subject: [PATCH] fix(do): return 200 records instead of default 20 In most cases 200 limit should be enough. It is extremely rare situation when there will be 200 dns records or more. And it might be due to a wrong configuration. If it will become something common, then its time to implement pagination. Closes: #24 --- do/do.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/do/do.go b/do/do.go index 6d76461..cd13493 100644 --- a/do/do.go +++ b/do/do.go @@ -9,6 +9,7 @@ import ( "net/http" "time" + log "github.com/sirupsen/logrus" "github.com/skibish/ddns/misc" ) @@ -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. @@ -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) } @@ -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 }