Documentation ¶
Overview ¶
Package pagination contains utilities and convenience structs that implement common pagination idioms within OpenStack APIs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Request ¶
func Request(client *gophercloud.ServiceClient, headers map[string]string, url string) (*http.Response, error)
Request performs an HTTP request and extracts the http.Response from the result.
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() interface{}
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.
func (LinkedPageBase) WrapNextPageURL ¶
func (current LinkedPageBase) WrapNextPageURL(markerID string) (string, error)
WrapNextPageURL function use makerID to warp next page url,it returns the full url for request.
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() interface{}
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 NumberPage ¶
NumberPage is a stricter Page interface that describes additional functionality required for use with NewNumberPage. For convenience, embed the NumberPageBase struct.
type NumberPageBase ¶
type NumberPageBase struct { PageResult Owner NumberPage }
NumberPageBase is a page in a collection that's paginated by "limit" and "start_number" query parameters.
func (NumberPageBase) GetBody ¶
func (current NumberPageBase) GetBody() interface{}
GetBody returns the linked page's body. This method is needed to satisfy the Page interface.
func (NumberPageBase) IsEmpty ¶
func (current NumberPageBase) IsEmpty() (bool, error)
IsEmpty satisifies the IsEmpty method of the Page interface
func (NumberPageBase) NextPageURL ¶
func (current NumberPageBase) NextPageURL() (string, error)
NextPageURL generates the URL for the page of results after this one.
type Offset ¶ added in v1.0.18
type Offset struct {
PageResult
}
OffsetPage is a page in a collection that's paginated by "limit" and "offset" query parameters.
func (Offset) GetBody ¶ added in v1.0.18
func (current Offset) GetBody() interface{}
GetBody returns the linked page's body. This method is needed to satisfy the Page interface.
func (Offset) NextPageURL ¶ added in v1.0.18
NextPageURL always returns "" to indicate that there are no more pages to return.
type OffsetPage ¶
type OffsetPage struct {
PageResult
}
OffsetPage is a page in a collection that's paginated by "limit" and "offset" query parameters.
func (OffsetPage) GetBody ¶
func (current OffsetPage) GetBody() interface{}
GetBody returns the linked page's body. This method is needed to satisfy the Page interface.
func (OffsetPage) IsEmpty ¶
func (current OffsetPage) IsEmpty() (bool, error)
IsEmpty satisfies the IsEmpty method of the Page interface
func (OffsetPage) NextPageURL ¶
func (current OffsetPage) NextPageURL() (string, error)
NextPageURL always returns "" to indicate that there are no more pages to return.
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() interface{} }
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 ¶
type PageResult struct { gophercloud.Result url.URL }
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 interface{}) 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 ¶
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() interface{}
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.