blob: f355afc54b57da607491b2211bcc57a97417d02b [file] [log] [blame]
Ash Wilsonc8e68872014-09-16 10:36:56 -04001package pagination
2
Ash Wilsonc8e68872014-09-16 10:36:56 -04003// 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
Ash Wilson74863512014-09-16 11:45:51 -04008 // LastMarker returns the last "marker" value on this page.
9 LastMarker() (string, error)
Ash Wilsonc8e68872014-09-16 10:36:56 -040010}
11
12// MarkerPageBase is a page in a collection that's paginated by "limit" and "marker" query parameters.
13type MarkerPageBase struct {
Ash Wilsonb8b16f82014-10-20 10:19:49 -040014 PageResult
Ash Wilsonc8e68872014-09-16 10:36:56 -040015
Ash Wilson58c4f672014-09-16 11:50:56 -040016 // Owner is a reference to the embedding struct.
17 Owner MarkerPage
Ash Wilsonc8e68872014-09-16 10:36:56 -040018}
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
Ash Wilson58c4f672014-09-16 11:50:56 -040024 mark, err := current.Owner.LastMarker()
Ash Wilsonc8e68872014-09-16 10:36:56 -040025 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}
Jon Perrittdb319f12015-02-17 19:32:40 -070035
36// GetBody returns the linked page's body. This method is needed to satisfy the
37// Page interface.
38func (current MarkerPageBase) GetBody() interface{} {
39 return current.Body
40}