Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit a768df7

Browse files
authored
fix: return first page of list results even if Link header is missing (#23)
This fixes #19 by making sure the `pageIterator` always returns the first page of results, even if it doesn't have a `Link` header. The API only sends the header if you have more than one page of results, so list was broken if you had less than a page.
1 parent 4828c8b commit a768df7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

list.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,23 @@ func newPageIterator(url string, fetchNextPage func(string) (*http.Response, err
121121
}
122122

123123
func (pi *pageIterator) Next() (*http.Response, error) {
124+
if pi.nextURL == "" {
125+
return nil, io.EOF
126+
}
124127
res, err := pi.fetchNextPage(pi.nextURL)
125128
if err != nil {
126129
return nil, err
127130
}
128131
linkHdrs := res.Header["Link"]
129-
if len(linkHdrs) == 0 {
130-
return nil, io.EOF
131-
}
132-
links := linkheader.Parse(linkHdrs[0])
133-
for _, l := range links {
134-
if l.Rel == "next" {
135-
pi.nextURL = links[0].URL
136-
return res, nil
132+
pi.nextURL = ""
133+
if len(linkHdrs) > 0 {
134+
links := linkheader.Parse(linkHdrs[0])
135+
for _, l := range links {
136+
if l.Rel == "next" {
137+
pi.nextURL = l.URL
138+
break
139+
}
137140
}
138141
}
139-
return nil, io.EOF
142+
return res, nil
140143
}

0 commit comments

Comments
 (0)