Documentation ¶
Index ¶
- Constants
- func CurrentPage(offset int64, limit int64) int64
- func LimitAndOffset(query url.Values) (int64, int64, int, error)
- func MaxOffset(total int64, limit int64) int64
- func OffsetFromPage(page int64, limit int64) (offset int64)
- func PageCount(total int64, limit int64) int64
- type Core
- type Pagination
Constants ¶
const ( // DefaultLimit defines the default number of items per page for APIs DefaultLimit int64 = 25 // DefaultOffset defines the default offset for API responses DefaultOffset int64 = 0 )
Variables ¶
This section is empty.
Functions ¶
func CurrentPage ¶
CurrentPage returns the current page for a given offset and limit value
func LimitAndOffset ¶
LimitAndOffset returns the Limit and Offset for a given request querystring
func MaxOffset ¶
MaxOffset returns the maximum possible offset for a given number of pages and limit per page
func OffsetFromPage ¶
OffsetFromPage returns the offset from a page number. This helps older interfaces continue to support pageNumber and perPage parameters whilst we would use limit and offset internally.
Types ¶
type Core ¶
type Core struct { Total int64 `json:"total"` Limit int64 `json:"limit"` Offset int64 `json:"offset"` MaxOffset int64 `json:"maxOffset"` Pages int64 `json:"totalPages"` Page int64 `json:"page"` Type string `json:"type"` }
Core contains the fields that encapsulate pagination of arrays
type Pagination ¶
type Pagination struct { Core Items interface{} `json:"items"` }
Pagination describes an array in JSON and how to paginate the collection NOTE: You are advised to use your own strongly typed one, this one is only good for marshalling to JSON and cannot be used to marshal back to an object as it uses an interface{} for the Items