pagination

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package pagination drives offset/limit iteration for list endpoints.

The Timestripe API exposes offset/limit pagination with a total count. Callers pass a Fetcher that performs a single page request; Fetch walks the result set up to Options.Limit (or until exhausted when --all is set).

Index

Constants

View Source
const DefaultLimit = 30

DefaultLimit is the number of items returned when --limit is not provided. Chosen to be small enough for quick inspection and large enough to be useful.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope[T any] struct {
	PageInfo PageInfo `json:"pageInfo" yaml:"pageInfo"`
	Items    []T      `json:"items"    yaml:"items"`
}

Envelope is the canonical JSON list response shape.

func Fetch

func Fetch[T any](ctx context.Context, fn Fetcher[T], opts Options) (*Envelope[T], error)

Fetch walks pages until the limit is reached or results are exhausted.

type Fetcher

type Fetcher[T any] func(ctx context.Context, limit, offset int) (*Page[T], error)

Fetcher performs a single paginated request.

type Options

type Options struct {
	// Limit is the total number of items to return. Ignored when All is true.
	Limit int
	// Offset is the starting offset into the result set.
	Offset int
	// All iterates until the server reports no more results.
	All bool
}

Options tunes the iteration. Zero values mean "use defaults".

type Page

type Page[T any] struct {
	Count    int
	Next     *string
	Previous *string
	Results  []T
}

Page is one page of results as returned by a Fetcher.

type PageInfo

type PageInfo struct {
	Count    int     `json:"count"              yaml:"count"`
	HasMore  bool    `json:"hasMore"            yaml:"hasMore"`
	Next     *string `json:"next,omitempty"     yaml:"next,omitempty"`
	Previous *string `json:"previous,omitempty" yaml:"previous,omitempty"`
}

PageInfo is the list metadata included in JSON/YAML output envelopes.

Jump to

Keyboard shortcuts

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