pagination

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2015 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pagination contains utilities and convenience structs that implement common pagination idioms within OpenStack APIs.

Index

Constants

This section is empty.

Variables

View Source
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

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 added in v0.13.0

func (current LinkedPageBase) GetBody() interface{}

GetBody returns the linked page's body. This method is needed to satisfy 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 added in v0.13.0

func (current MarkerPageBase) GetBody() interface{}

GetBody returns the linked page's body. This method is needed to satisfy 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() 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.

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 added in v0.13.0

func (p Pager) AllPages() (Page, error)

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(handler func(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 added in v0.13.0

func (current SinglePageBase) GetBody() interface{}

GetBody returns the single page's body. This method is needed to satisfy 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL