pagination

package
v0.0.0-...-60a913f Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2015 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
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

func CurrentPage(offset int64, limit int64) int64

CurrentPage returns the current page for a given offset and limit value

func LimitAndOffset

func LimitAndOffset(query url.Values) (int64, int64, int, error)

LimitAndOffset returns the Limit and Offset for a given request querystring

func MaxOffset

func MaxOffset(total int64, limit int64) int64

MaxOffset returns the maximum possible offset for a given number of pages and limit per page

func OffsetFromPage

func OffsetFromPage(page int64, limit int64) (offset int64)

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.

func PageCount

func PageCount(total int64, limit int64) int64

PageCount returns the number of pages for a given total and items per page

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

func (*Core) Populate

func (m *Core) Populate(
	total int64,
	limit int64,
	offset int64,
	contentType string,
)

Populate will populate the pagination fields of an array without setting the items

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

func Construct

func Construct(
	resources interface{},
	contentType string,
	total int64,
	limit int64,
	offset int64,
) Pagination

Construct returns a Pagination fully populated

Jump to

Keyboard shortcuts

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