github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/pagination/marker.go (about) 1 package pagination 2 3 import ( 4 "fmt" 5 ) 6 7 // MarkerPage is a stricter Page interface that describes additional functionality required for use with NewMarkerPager. 8 // For convenience, embed the MarkedPageBase struct. 9 type MarkerPage interface { 10 Page 11 12 // LastMarker returns the last "marker" value on this page. 13 LastMarker() (string, error) 14 } 15 16 // MarkerPageBase is a page in a collection that's paginated by "limit" and "marker" query parameters. 17 type MarkerPageBase struct { 18 PageResult 19 20 // Owner is a reference to the embedding struct. 21 Owner MarkerPage 22 } 23 24 // NextPageURL generates the URL for the page of results after this one. 25 func (current MarkerPageBase) NextPageURL() (string, error) { 26 currentURL := current.URL 27 28 mark, err := current.Owner.LastMarker() 29 if err != nil { 30 return "", err 31 } 32 33 q := currentURL.Query() 34 q.Set("marker", mark) 35 currentURL.RawQuery = q.Encode() 36 37 return currentURL.String(), nil 38 } 39 40 // IsEmpty satisifies the IsEmpty method of the Page interface 41 func (current MarkerPageBase) IsEmpty() (bool, error) { 42 body, err := current.GetBodyAsSlice() 43 if err != nil { 44 return false, fmt.Errorf("error converting page body to slice: %w", err) 45 } 46 47 return len(body) == 0, nil 48 } 49 50 // GetBody returns the linked page's body. This method is needed to satisfy the 51 // Page interface. 52 func (current MarkerPageBase) GetBody() []byte { 53 return current.Body 54 }