Documentation ¶
Overview ¶
Package pagination provides support for pagination requests and responses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultPageSize specifies the default page size DefaultPageSize = 100 // MaxPageSize specifies the maximum page size MaxPageSize = 1000 // PageVar specifies the query parameter name for page number PageVar = "page" // PageSizeVar specifies the query parameter name for page size PageSizeVar = "per_page" )
Functions ¶
This section is empty.
Types ¶
type Pages ¶
type Pages struct { Page int `json:"page"` PerPage int `json:"per_page"` PageCount int `json:"page_count"` TotalCount int `json:"total_count"` Items interface{} `json:"items"` }
Pages represents a paginated list of data items.
func New ¶
New creates a new Pages instance. The page parameter is 1-based and refers to the current page index/number. The perPage parameter refers to the number of items on each page. And the total parameter specifies the total number of data items. If total is less than 0, it means total is unknown.
func NewFromRequest ¶
NewFromRequest creates a Pages object using the query parameters found in the given HTTP request. count stands for the total number of items. Use -1 if this is unknown.
func (*Pages) BuildLinkHeader ¶
BuildLinkHeader returns an HTTP header containing the links about the pagination.
func (*Pages) BuildLinks ¶
BuildLinks returns the first, prev, next, and last links corresponding to the pagination. A link could be an empty string if it is not needed. For example, if the pagination is at the first page, then both first and prev links will be empty.