Documentation ¶
Overview ¶
Package pagination defines pagination helpers.
Index ¶
Constants ¶
const ( // QueryKeyPage is the URL querystring for the current page. QueryKeyPage = "page" // QueryKeyLimit is the URL querystring for the current per-page limit. QueryKeyLimit = "limit" // DefaultLimit is the default pagination limit, if one is not provided. DefaultLimit = uint64(24) // MaxLimit is the maximum size for a single pagination. If a limit higher // than this is provided, it's capped. MaxLimit = uint64(100) )
Variables ¶
var UnlimitedResults = &PageParams{ Page: 1, Limit: math.MaxInt64, }
UnlimitedResults is a paginator that doesn't do pagination and returns all results (up to (1<<63)-1).
Functions ¶
This section is empty.
Types ¶
type Page ¶
type Page struct { // Number is the numerical page number. Number uint64 }
Page represents a single page.
type PageParams ¶
type PageParams struct { // Page is the current page. Page uint64 // Limit is the per-page limit. Limit uint64 }
PageParams are the page parameters including the current page and per page limit.
func FromRequest ¶
func FromRequest(r *http.Request) (*PageParams, error)
FromRequest builds the PageParams from an http.Request. If there are no pagination parameters, the struct is returned with the default values.
type Paginator ¶
type Paginator struct { PrevPage *Page PrevPages []*Page CurrPage *Page NextPages []*Page NextPage *Page }
Paginator is a meta-struct that holds pagination information. It's largely a collection of pointers to Page structs. You may notice some repetition across fields - this is to make the struct easier to use inside Go template's where simple features like "get the last element of a slice" are actually very hard.