Documentation ¶
Overview ¶
Package pagination provides helpers for dealing with pagination.
Index ¶
- func Header(w http.ResponseWriter, u *url.URL, total int, limit, offset int)
- func HeaderWithFormatter(w http.ResponseWriter, u *url.URL, total int64, page, itemsPerPage int, ...)
- func Index(limit, offset, length int) (start, end int)
- func MaxItemsPerPage(max, is int) int
- func Parse(r *http.Request, defaultLimit, defaultOffset, maxLimit int) (int, int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Header ¶ added in v0.0.45
Header adds an http header for pagination using a responsewriter where backwards compatibility is required. The header will contain links any combination of the first, last, next, or previous (prev) pages in a paginated list (given a limit and an offset, and optionally a total). If total is not set, then no "last" page will be calculated. If no limit is provided, then it will default to 1.
func HeaderWithFormatter ¶ added in v0.0.509
func HeaderWithFormatter(w http.ResponseWriter, u *url.URL, total int64, page, itemsPerPage int, f formatter)
HeaderWithFormatter adds an HTTP header for pagination which uses a custom formatter for generating the URL links.
func Index ¶
Index uses limit, offset, and a slice's length to compute start and end indices for said slice.
func MaxItemsPerPage ¶ added in v0.0.307
MaxItemsPerPage is used to prevent DoS attacks against large lists by limiting the items per page to 500.
Types ¶
This section is empty.