Skip to content

Commit

Permalink
Add paging to record list
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Peterson authored Aug 31, 2017
1 parent 9450476 commit 4f6fcd5
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions domain/zone/record/record.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package record

import "github.com/prasmussen/gandi-api/client"
import (
"github.com/prasmussen/gandi-api/client"
)

type Record struct {
*client.Client
Expand All @@ -22,16 +24,25 @@ func (self *Record) Count(zoneId, version int64) (int64, error) {

// List records of a version of a DNS zone
func (self *Record) List(zoneId, version int64) ([]*RecordInfo, error) {
var res []interface{}
params := []interface{}{self.Key, zoneId, version}
if err := self.Call("domain.zone.record.list", params, &res); err != nil {
return nil, err
}

opts := &struct {
Page int `xmlrpc:"page"`
}{0}
const perPage = 100
params := []interface{}{self.Key, zoneId, version, opts}
records := make([]*RecordInfo, 0)
for _, r := range res {
record := ToRecordInfo(r.(map[string]interface{}))
records = append(records, record)
for {
var res []interface{}
if err := self.Call("domain.zone.record.list", params, &res); err != nil {
return nil, err
}
for _, r := range res {
record := ToRecordInfo(r.(map[string]interface{}))
records = append(records, record)
}
if len(res) < perPage {
break
}
opts.Page++
}
return records, nil
}
Expand Down

0 comments on commit 4f6fcd5

Please sign in to comment.