...

Package pagination

import "github.com/ory/x/pagination"
Overview
Index

Overview ▾

Package pagination provides helpers for dealing with pagination.

func Header(w http.ResponseWriter, u *url.URL, total int, limit, offset int)

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 Index

func Index(limit, offset, length int) (start, end int)

Index uses limit, offset, and a slice's length to compute start and end indices for said slice.

func Parse

func Parse(r *http.Request, defaultLimit, defaultOffset, maxLimit int) (int, int)

Parse parses limit and offset from *http.Request with given limits and defaults.