Documentation ¶
Overview ¶
Package pagination contains utilities and convenience structs that implement common pagination idioms within OpenStack APIs.
Index ¶
- func Request(client *golangsdk.ServiceClient, headers map[string]string, url string) (*http.Response, error)
- type LinkedPageBase
- type MarkerPage
- type MarkerPageBase
- type NewPage
- type NewPageResult
- type NewSinglePageBase
- type OffsetPage
- type OffsetPageBase
- type Page
- type PageResult
- type PageWithInfo
- type Pager
- type SinglePageBase
- func (current SinglePageBase) GetBody() []byte
- func (current SinglePageBase) GetBodyAsMap() (map[string]interface{}, error)
- func (current SinglePageBase) GetBodyAsSlice() ([]interface{}, error)
- func (current SinglePageBase) IsEmpty() (bool, error)
- func (current SinglePageBase) NextPageURL() (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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() []byte
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 satisfies 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() []byte
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 NewPage ¶ added in v0.9.0
type NewPage interface { // NewNextPageURL generates the URL for the page of data that follows this collection. // Return "" if no such page exists. NewNextPageURL() (string, error) // NewIsEmpty returns true if this Page has no items in it. NewIsEmpty() (bool, error) // NewGetBody returns the Page Body. This is used in the `AllPages` method. NewGetBody() []byte // NewGetBodyAsSlice tries to convert page body to a slice. NewGetBodyAsSlice() ([]any, error) // NewGetBodyAsMap tries to convert page body to a map. NewGetBodyAsMap() (map[string]any, error) }
NewPage 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 NewPageResult ¶ added in v0.9.0
type NewPageResult struct { // Body is the payload of the HTTP response from the server. Body []byte // Header contains the HTTP header structure from the original response. Header http.Header URL url.URL }
NewPageResult stores the HTTP response that returned the current page of results.
func (NewPageResult) NewGetBody ¶ added in v0.9.0
func (r NewPageResult) NewGetBody() []byte
func (NewPageResult) NewGetBodyAsMap ¶ added in v0.9.0
func (r NewPageResult) NewGetBodyAsMap() (map[string]any, error)
NewGetBodyAsMap tries to convert page body to a map, returning nil on fail
func (NewPageResult) NewGetBodyAsSlice ¶ added in v0.9.0
func (r NewPageResult) NewGetBodyAsSlice() ([]any, error)
NewGetBodyAsSlice tries to convert page body to a slice, returning nil on fail
type NewSinglePageBase ¶ added in v0.9.0
type NewSinglePageBase struct {
NewPageResult
}
NewSinglePageBase may be embedded in a Page that contains all the results from an operation at once.
func (NewSinglePageBase) NewIsEmpty ¶ added in v0.9.0
func (current NewSinglePageBase) NewIsEmpty() (bool, error)
NewIsEmpty satisfies the IsEmpty method of the Page interface
func (NewSinglePageBase) NewNextPageURL ¶ added in v0.9.0
func (current NewSinglePageBase) NewNextPageURL() (string, error)
NewNextPageURL always returns "" to indicate that there are no more pages to return.
type OffsetPage ¶ added in v0.5.0
type OffsetPage interface { // LastElement returning index of the last element of the page LastElement() int }
type OffsetPageBase ¶ added in v0.5.0
type OffsetPageBase struct { Offset int Limit int PageResult }
func (OffsetPageBase) GetBody ¶ added in v0.5.0
func (p OffsetPageBase) GetBody() []byte
GetBody returns the Page Body. This is used in the `AllPages` method.
func (OffsetPageBase) IsEmpty ¶ added in v0.5.0
func (p OffsetPageBase) IsEmpty() (bool, error)
IsEmpty returns true if this Page has no items in it.
func (OffsetPageBase) LastElement ¶ added in v0.5.0
func (p OffsetPageBase) LastElement() int
func (OffsetPageBase) NextPageURL ¶ added in v0.5.0
func (p OffsetPageBase) NextPageURL() (string, error)
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() []byte // GetBodyAsSlice tries to convert page body to a slice. GetBodyAsSlice() ([]any, error) // GetBodyAsMap tries to convert page body to a map. GetBodyAsMap() (map[string]any, error) }
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 (PageResult) GetBody ¶ added in v0.9.0
func (r PageResult) GetBody() []byte
func (PageResult) GetBodyAsMap ¶ added in v0.5.22
func (r PageResult) GetBodyAsMap() (map[string]any, error)
GetBodyAsMap tries to convert page body to a map, returning nil on fail
func (PageResult) GetBodyAsSlice ¶ added in v0.5.22
func (r PageResult) GetBodyAsSlice() ([]any, error)
GetBodyAsSlice tries to convert page body to a slice, returning nil on fail
type PageWithInfo ¶ added in v0.5.5
type PageWithInfo struct {
MarkerPageBase
}
PageWithInfo is a page with marker information inside `page_info`
func NewPageWithInfo ¶ added in v0.5.5
func NewPageWithInfo(r PageResult) PageWithInfo
func (PageWithInfo) LastMarker ¶ added in v0.5.5
func (p PageWithInfo) LastMarker() (string, error)
func (PageWithInfo) NextPageURL ¶ added in v0.5.5
func (p PageWithInfo) NextPageURL() (string, error)
NextPageURL generates the URL for the page of results after this one.
type Pager ¶
type Pager struct { Client *golangsdk.ServiceClient InitialURL string CreatePage func(r NewPageResult) NewPage 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 *golangsdk.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) NewAllPages ¶ added in v0.9.0
NewAllPages returns all the pages from a `List` operation in a single page, allowing the user to retrieve all the pages at once.
type SinglePageBase ¶
type SinglePageBase PageResult
SinglePageBase may be embedded in a Page that contains all the results from an operation at once. Deprecated: use element slice as a return result.
func (SinglePageBase) GetBody ¶
func (current SinglePageBase) GetBody() []byte
func (SinglePageBase) GetBodyAsMap ¶ added in v0.5.22
func (current SinglePageBase) GetBodyAsMap() (map[string]interface{}, error)
func (SinglePageBase) GetBodyAsSlice ¶ added in v0.5.22
func (current SinglePageBase) GetBodyAsSlice() ([]interface{}, error)
func (SinglePageBase) IsEmpty ¶
func (current SinglePageBase) IsEmpty() (bool, error)
IsEmpty satisfies 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.