pagination

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pagination provides support for pagination requests and responses.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPageSize specifies the default page size
	DefaultPageSize = 30
	// MaxPageSize specifies the maximum page size
	MaxPageSize = 100
	// 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 {
	Pagination `json:"pagination"`
	Items      any `json:"items"`
}

func New

func New(page, perPage, total int) *Pages

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

func NewFromRequest(req *http.Request, count int) *Pages

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

func (p *Pages) BuildLinkHeader(baseURL string, defaultPerPage int) string

BuildLinkHeader returns an HTTP header containing the links about the pagination.

func (p *Pages) BuildLinks(baseURL string, defaultPerPage int) [4]string

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.

func (*Pages) Limit

func (p *Pages) Limit() int64

Limit returns the LIMIT value that can be used in a SQL statement.

func (Pages) MarshalEasyJSON

func (v Pages) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Pages) MarshalJSON

func (v Pages) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Pages) Offset

func (p *Pages) Offset() int64

Offset returns the OFFSET value that can be used in a SQL statement.

func (*Pages) UnmarshalEasyJSON

func (v *Pages) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Pages) UnmarshalJSON

func (v *Pages) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Pagination

type Pagination struct {
	Page       int `json:"page"`
	PerPage    int `json:"per_page"`
	PageCount  int `json:"page_count"`
	TotalCount int `json:"total_count"`
}

Pagination represents pagination details of items.

func (Pagination) MarshalEasyJSON

func (v Pagination) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Pagination) MarshalJSON

func (v Pagination) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Pagination) UnmarshalEasyJSON

func (v *Pagination) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Pagination) UnmarshalJSON

func (v *Pagination) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL