pagination

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

package pagination implements a cursor-based pagination for the REST API, where the cursors are opaque strings that encode an index in a result set.

Index

Constants

View Source
const (
	DefaultPageSize = 40
)

Variables

This section is empty.

Functions

func DefaultPaginate

func DefaultPaginate[T any](ctx context.Context, lst []T) ([]T, models.PaginationInfo)

Returns the result of Paginate with a page size of DefaultPageSize

func Paginate

func Paginate[T any](ctx context.Context, lst []T, spec *models.PaginationSpec) ([]T,
	models.PaginationInfo, error)

Returns a single page from the input, selected using the given pagination spec, along with a struct describing the pagination of the returned page. The input result set should be the same for every call that uses chained PaginationSpecs and PaginationInfos. If spec is nil, a default page size is used.

Errors are suitable to directly return to clients. An error is returned only if:

  • the cursor is the empty string
  • the cursor decodes to an out of bounds index in the input
  • the cursor can't be decoded
  • PageSize < 0

func PointerOf

func PointerOf[T any](val T) *T

Types

This section is empty.

Jump to

Keyboard shortcuts

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