pagination

command
v14.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

A complete list endpoint in one call: ctx.Paginated.

Paginated reads ?page=&size=&details= into an iris.PageOptions, reads the OPTIONAL JSON filter body next to it, runs your collector and renders the iris.Page[T] envelope. The collector receives the parsed options and returns the window plus the total count of matches.

opts.GetLimit() is Size bounded by pagination.MaxPageSize, falling back to pagination.DefaultPageSize (100) when Size is zero, both settable through iris.Patches().Context(); opts.GetOffset() derives the offset from Page. Feed both to a database query - here to a slice.

QUERY (RFC 10008) is the method for the filtered form: a safe, cacheable request that carries a body.

Learn: serve a paged list with an optional filter body and the Page[T] envelope from one collector function. Before: ../strict-query

Run:

go run main.go

Try:

curl 'http://localhost:8080/books?page=1&size=2'   # 200, items 1-2 of 5, has_next_page true
curl 'http://localhost:8080/books?page=2&size=2'   # 200, items 3-4 of 5
curl -X QUERY 'http://localhost:8080/books?page=1&size=2' \
  -H 'Content-Type: application/json' -d '{"author":"Kurt Vonnegut"}'   # 200, the two Vonnegut books, total_items 2

The envelope ("page_size" is how many items THIS page carries):

{
  "current_page": 1, "page_size": 2, "total_pages": 3, "total_items": 5,
  "has_next_page": true,
  "filter": {"author": ""},
  "items": [{"title":"...","author":"..."}, {...}]
}

Next: ../uploads

Jump to

Keyboard shortcuts

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