blob: 41b493ada12b0b51eb17d92fa06df6046d0288cc [file] [log] [blame]
Jamie Hannaford8c072a32014-10-16 14:33:32 +02001package pagination
2
3// MarkerPage is a stricter Page interface that describes additional functionality required for use with NewMarkerPager.
4// For convenience, embed the MarkedPageBase struct.
5type MarkerPage interface {
6 Page
7
8 // LastMarker returns the last "marker" value on this page.
9 LastMarker() (string, error)
10}
11
12// MarkerPageBase is a page in a collection that's paginated by "limit" and "marker" query parameters.
13type MarkerPageBase struct {
14 LastHTTPResponse
15
16 // Owner is a reference to the embedding struct.
17 Owner MarkerPage
18}
19
20// NextPageURL generates the URL for the page of results after this one.
21func (current MarkerPageBase) NextPageURL() (string, error) {
22 currentURL := current.URL
23
24 mark, err := current.Owner.LastMarker()
25 if err != nil {
26 return "", err
27 }
28
29 q := currentURL.Query()
30 q.Set("marker", mark)
31 currentURL.RawQuery = q.Encode()
32
33 return currentURL.String(), nil
34}