pagination

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteResponse

func WriteResponse(w http.ResponseWriter, res PagingResponse) error

WriteResponse writes to http.ResponseWriter the pagination values determined by PagingResponse.

Types

type PagingLinks struct {
	// First contains the URL where clients should query the first page of elements.
	First *url.URL
	// Previous contains the URL where clients should query the first page of elements.
	Previous *url.URL
	// Next contains the URL where clients should query the first page of elements.
	Next *url.URL
	// Last contains the URL where clients should query the first page of elements.
	Last *url.URL
}

PagingLinks contains a set of URLs to help with pagination.

func (PagingLinks) ToLinkHeaders

func (p PagingLinks) ToLinkHeaders() []string

ToLinkHeaders converts the links in PagingLinks to an array of links to use in the "Link" HTTP header.

type PagingRequest

type PagingRequest struct {
	// Page is the page that should be shown. When using ReadRequest, this value defaults to 1.
	Page uint64
	// PageSize contains the amount of elements that a Page will include. When using ReadRequest, this value defaults to 30.
	PageSize uint64
}

PagingRequest is used to describe pagination values from incoming requests.

func ReadRequest

func ReadRequest(r *http.Request) PagingRequest

ReadRequest reads the PagingRequest from a http.Request.

type PagingResponse

type PagingResponse struct {
	// BaseURL contains the base url that should be used to interact with the desired API list method that supports pagination.
	// If BaseURL contains query params for page and page_size, those values will be overwritten.
	BaseURL *url.URL
	// Page contains the page that was requested.
	Page uint64
	// PageSize contains the amount of elements that were requested for this Page.
	PageSize uint64
	// Count contains the amount of elements that were retrieved for this Page.
	Count uint64
	// TotalCount contains the elements available, usually used to calculate the amount of pages available.
	TotalCount uint64
}

PagingResponse contains the values that should be added to an HTTP response.

func (r PagingResponse) ToPagingLinks() PagingLinks

ToPagingLinks converts the current PagingResponse to a group of links described by PagingLinks.

Jump to

Keyboard shortcuts

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