Documentation ¶
Overview ¶
Package pagination contains utilities and convenience structs that implement common pagination idioms within OpenStack APIs.
Index ¶
- Constants
- Variables
- func ListAllItems(client *golangsdk.ServiceClient, qType string, initialURL string, ...) (interface{}, error)
- func Request(client *golangsdk.ServiceClient, headers map[string]string, url string) (*http.Response, error)
- type LinkedPageBase
- type MarkerPage
- type MarkerPageBase
- type OffsetPage
- type OffsetPageBase
- type Page
- type PageResult
- type PageSizeBase
- type Pager
- type QueryOpts
- type SinglePageBase
Constants ¶
const ( Marker string = "marker" // limit + marker Offset = "offset" // limit + offset PageSize = "page" // pagesize + page )
the query type that can be supported
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.") // the maximum pager is 1000 MaxPager = 1000 )
Functions ¶
func ListAllItems ¶
func ListAllItems(client *golangsdk.ServiceClient, qType string, initialURL string, opts *QueryOpts) (interface{}, error)
ListAllItems is the method to get all pages from initialURL
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 // contains filtered or unexported fields }
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) LastMarker ¶
func (current MarkerPageBase) LastMarker() (string, error)
LastMarker method returns the last ID in a page.
func (MarkerPageBase) NextPageURL ¶
func (current MarkerPageBase) NextPageURL() (string, error)
NextPageURL generates the URL for the page of results after this one.
type OffsetPage ¶
OffsetPage is used for paging queries based on offset and limit.
type OffsetPageBase ¶
type OffsetPageBase struct { PageResult DefaultOffset int DefaultLimit int }
OffsetPageBase is used for paging queries based on offset and limit. DefaultOffset and DefaultLimit are used to calculate the next offset
func (OffsetPageBase) GetBody ¶
func (current OffsetPageBase) GetBody() interface{}
GetBody returns the page's body. This method is needed to satisfy the Page interface.
func (OffsetPageBase) IsEmpty ¶
func (current OffsetPageBase) IsEmpty() (bool, error)
IsEmpty satisifies the IsEmpty method of the Page interface.
func (OffsetPageBase) NextOffset ¶
func (current OffsetPageBase) NextOffset() int
NextOffset returns offset of the next element of the page.
func (OffsetPageBase) NextPageURL ¶
func (current OffsetPageBase) 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() 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 ¶
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 PageSizeBase ¶
type PageSizeBase struct {
PageResult
}
PageSizeBase is used for paging queries based on "page" and "pageSize". You can change the parameter name of the current page number by overriding the GetPageName method.
func (PageSizeBase) GetBody ¶
func (current PageSizeBase) GetBody() interface{}
GetBody returns the linked page's body. This method is needed to satisfy the Page interface.
func (PageSizeBase) GetPageName ¶
func (current PageSizeBase) GetPageName() string
GetPageName Overwrite this function for changing the parameter name of the current page number Default value is "page"
func (PageSizeBase) IsEmpty ¶
func (current PageSizeBase) IsEmpty() (bool, error)
IsEmpty satisifies the IsEmpty method of the Page interface
func (PageSizeBase) NextPageURL ¶
func (current PageSizeBase) NextPageURL() (string, error)
NextPageURL generates the URL for the page of results after this one.
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 *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) 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 QueryOpts ¶
type QueryOpts struct {
MarkerField string
}
QueryOpts is the operation for ListAllItems currently, you can change the default marker field with `MarkerField`
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.