Documentation ¶
Overview ¶
Package pagination contains utilities and convenience structs that implement common pagination idioms within OpenStack APIs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPageNotAvailable is returned from a Pager when a next or previous page is requested, but does not exist. ErrPageNotAvailable = errors.New("The requested page does not exist.") )
Functions ¶
Types ¶
type LinkedPageBase ¶
type LinkedPageBase struct { PageResult // LinkPath lists the keys that should be traversed within a response to arrive at the "next" pointer. // If any link along the path is missing, an empty URL will be returned. // If any link results in an unexpected value type, an error will be returned. // When left as "nil", []string{"links", "next"} will be used as a default. LinkPath []string }
LinkedPageBase may be embedded to implement a page that provides navigational "Next" and "Previous" links within its result.
func (LinkedPageBase) GetBody ¶
func (current LinkedPageBase) GetBody() any
GetBody returns the linked page's body. This method is needed to satisfy the Page interface.
func (LinkedPageBase) IsEmpty ¶
func (current LinkedPageBase) IsEmpty() (bool, error)
IsEmpty satisifies the IsEmpty method of the Page interface
func (LinkedPageBase) NextPageURL ¶
func (current LinkedPageBase) NextPageURL() (string, error)
NextPageURL extracts the pagination structure from a JSON response and returns the "next" link, if one is present. It assumes that the links are available in a "links" element of the top-level response object. If this is not the case, override NextPageURL on your result type.
type MarkerPage ¶
type MarkerPage interface { Page // LastMarker returns the last "marker" value on this page. LastMarker() (string, error) }
MarkerPage is a stricter Page interface that describes additional functionality required for use with NewMarkerPager. For convenience, embed the MarkedPageBase struct.
type MarkerPageBase ¶
type MarkerPageBase struct { PageResult // Owner is a reference to the embedding struct. Owner MarkerPage }
MarkerPageBase is a page in a collection that's paginated by "limit" and "marker" query parameters.
func (MarkerPageBase) GetBody ¶
func (current MarkerPageBase) GetBody() any
GetBody returns the linked page's body. This method is needed to satisfy the Page interface.
func (MarkerPageBase) IsEmpty ¶
func (current MarkerPageBase) IsEmpty() (bool, error)
IsEmpty satisifies the IsEmpty method of the Page interface
func (MarkerPageBase) NextPageURL ¶
func (current MarkerPageBase) NextPageURL() (string, error)
NextPageURL generates the URL for the page of results after this one.
type Page ¶
type Page interface { // NextPageURL generates the URL for the page of data that follows this collection. // Return "" if no such page exists. NextPageURL() (string, error) // IsEmpty returns true if this Page has no items in it. IsEmpty() (bool, error) // GetBody returns the Page Body. This is used in the `AllPages` method. GetBody() any }
Page must be satisfied by the result type of any resource collection. It allows clients to interact with the resource uniformly, regardless of whether or not or how it's paginated. Generally, rather than implementing this interface directly, implementors should embed one of the concrete PageBase structs, instead. Depending on the pagination strategy of a particular resource, there may be an additional subinterface that the result type will need to implement.
type PageResult ¶
PageResult stores the HTTP response that returned the current page of results.
func PageResultFrom ¶
func PageResultFrom(resp *http.Response) (PageResult, error)
PageResultFrom parses an HTTP response as JSON and returns a PageResult containing the results, interpreting it as JSON if the content type indicates.
func PageResultFromParsed ¶
func PageResultFromParsed(resp *http.Response, body any) PageResult
PageResultFromParsed constructs a PageResult from an HTTP response that has already had its body parsed as JSON (and closed).
type Pager ¶
type Pager struct { Err error // Headers supplies additional HTTP headers to populate on each paged request. Headers map[string]string // contains filtered or unexported fields }
Pager knows how to advance through a specific resource collection, one page at a time.
func NewPager ¶
func NewPager(client *gophercloud.ServiceClient, initialURL string, createPage func(r PageResult) Page) Pager
NewPager constructs a manually-configured pager. Supply the URL for the first page, a function that requests a specific page given a URL, and a function that counts a page.
func (Pager) AllPages ¶
AllPages returns all the pages from a `List` operation in a single page, allowing the user to retrieve all the pages at once.
func (Pager) EachPage ¶
func (p Pager) EachPage(ctx context.Context, handler func(context.Context, Page) (bool, error)) error
EachPage iterates over each page returned by a Pager, yielding one at a time to a handler function. Return "false" from the handler to prematurely stop iterating.
func (Pager) WithPageCreator ¶
func (p Pager) WithPageCreator(createPage func(r PageResult) Page) Pager
WithPageCreator returns a new Pager that substitutes a different page creation function. This is useful for overriding List functions in delegation.
type SinglePageBase ¶
type SinglePageBase PageResult
SinglePageBase may be embedded in a Page that contains all of the results from an operation at once.
func (SinglePageBase) GetBody ¶
func (current SinglePageBase) GetBody() any
GetBody returns the single page's body. This method is needed to satisfy the Page interface.
func (SinglePageBase) IsEmpty ¶
func (current SinglePageBase) IsEmpty() (bool, error)
IsEmpty satisifies the IsEmpty method of the Page interface
func (SinglePageBase) NextPageURL ¶
func (current SinglePageBase) NextPageURL() (string, error)
NextPageURL always returns "" to indicate that there are no more pages to return.