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

pagination

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package pagination is the one page shape of every module List.

Order rule: each module owns one order, used by both API surfaces. History (Broadcasts, Automations runs, events) lists newest first, by id descending; catalogues (Templates, Segments, Tags, ...) list ascending by id.

Index

Constants

View Source
const DefaultPage = 1

DefaultPage and DefaultPageSize are what a module caller without a request gets. The contract (PageQuery) declares the same defaults and the page size maximum, which ogen enforces before a handler runs.

View Source
const DefaultPageSize = 25

DefaultPageSize is the fallback for module callers that have no request. contract-copy: the contract declares the same default

Variables

This section is empty.

Functions

func Normalize

func Normalize(page, pageSize *int32) (normalPage, normalPageSize int)

func Offset

func Offset(page, pageSize int) int

func TotalPages

func TotalPages(totalItems, pageSize int) int

Types

type Page

type Page[T any] struct {
	Items      []T `json:"items"`
	Page       int `json:"page"`
	PageSize   int `json:"pageSize"`
	TotalItems int `json:"totalItems"`
	TotalPages int `json:"totalPages"`
}

func List

func List[T any](
	ctx context.Context,
	p Params,
	count func(context.Context) (int, error),
	fetch func(ctx context.Context, limit, offset int) ([]T, error),
) (Page[T], error)

List builds one page from two closures: the total count, and the rows for a limit and offset. Ent builders share no interface, hence closures. Items is never nil.

func Paginate

func Paginate[T any](items []T, page, pageSize *int32) Page[T]

Paginate returns the requested page of an in-memory slice (for small catalogues that are cheaper to load whole than to page in SQL). Items is never nil.

type Params

type Params struct {
	Page     int
	PageSize int
}

Params are normalized page params: Page >= 1, PageSize >= 1.

func ParamsOf

func ParamsOf(page, pageSize optional) Params

ParamsOf normalizes the generated optional page params, applying the defaults.

func (Params) Offset

func (p Params) Offset() int

Offset is the number of rows before the page.

Jump to

Keyboard shortcuts

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