Help us shape the future of Go! Take the 2026 Go Developer Survey

page

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package page holds the request and answer shape of a bounded list. It is a leaf package so the store, the domain packages and the API can all name a page without importing one another.

Index

Constants

View Source
const (
	DefaultLimit = 50
	MaxLimit     = 200
)

DefaultLimit and MaxLimit bound a paged list: a caller that asks for nothing gets fifty, and nobody gets more than two hundred in one call, so no request can pull a whole tenant's rows at once.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts struct {
	Limit  int
	Cursor string
}

Opts asks for one page. Cursor is the NextCursor of the previous page, or empty for the first. Pages run newest first: ids are time-ordered, and the cursor is the id the previous page ended on.

func (Opts) Normalize

func (o Opts) Normalize() Opts

Normalize applies the default and the ceiling.

type Page

type Page[T any] struct {
	Items      []T
	NextCursor string
}

Page is one page of a list and, when more remain, the cursor for the next.

func Cut

func Cut[T any](items []T, limit int, idOf func(T) string) Page[T]

Cut turns a fetch of limit+1 rows into a page: when the extra row is there, the page is cut to limit and the cursor is the last item's id.

Jump to

Keyboard shortcuts

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