Documentation
¶
Overview ¶
Package pagination defines a paginator able to return formatted responses enabling the API consumer to retrieve data in defined chunks
Index ¶
- Variables
- type Paginator
- func (p *Paginator) GetLastPage() int
- func (p *Paginator) GetOffset() int
- func (p *Paginator) GetPage() int
- func (p *Paginator) GetPerPage() int
- func (p *Paginator) GetTotal() int
- func (p *Paginator) PrepareResponse() *Response
- func (p *Paginator) SetPage(page int) error
- func (p *Paginator) SetPerPage(perPage int) error
- func (p *Paginator) SetTotal(total int) error
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCalculateOffset is used when the pagination offset could not be calculated. ErrCalculateOffset = errors.New("cannot calculate offset: insufficient data") // ErrCalculateLastPage is used when the pagination last page could not be calculated. ErrCalculateLastPage = errors.New("cannot calculate last page: insufficient data") )
Functions ¶
This section is empty.
Types ¶
type Paginator ¶
type Paginator struct {
// contains filtered or unexported fields
}
Paginator manages pagination of a data set.
func NewPaginator ¶
NewPaginator returns a new Paginator instance with the provided parameters set and returns an error if it fails.
func (*Paginator) GetLastPage ¶
GetLastPage returns the last possible page number.
func (*Paginator) GetPerPage ¶
GetPerPage returns the number of items per page.
func (*Paginator) PrepareResponse ¶
PrepareResponse returns a prepared pagination response.
func (*Paginator) SetPage ¶
SetPage sets the page field to the provided value and returns an error if anything fails
func (*Paginator) SetPerPage ¶
SetPerPage defines how many items per page the paginator will return, based on the supplied parameter, and will return an error if anything fails.
type Response ¶
type Response struct { Total int `json:"total"` // The total number of items. PerPage int `json:"per_page"` // Number of items displayed per page. CurrentPage int `json:"current_page"` // The current page number. LastPage int `json:"last_page"` // The number of the last possible page. NextPage *int `json:"next_page"` // The number of the next page (if possible). PrevPage *int `json:"prev_page"` // The number of the previous page (if possible). }
Response represents a pagination response.