paginate

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package paginate provides a thin generic skeleton for SDK pagination loops.

It removes the "for { call API; append; advance cursor; break-on-last }" boilerplate that every provider's region enumerator re-implements. The caller owns everything SDK-specific (cursor type, end-of-stream detection, item mapping); this package just drives the loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch[Item, Cursor any](
	ctx context.Context,
	fn func(ctx context.Context, cursor Cursor) (Page[Item, Cursor], error),
) ([]Item, error)

Fetch calls fn repeatedly starting from the zero value of Cursor, appending each page's Items to the result. It stops when fn returns Done=true, returns an error, or ctx is cancelled (already-collected items are returned, err nil on cancellation — matches the partial-failure convention used elsewhere).

Types

type Page

type Page[Item, Cursor any] struct {
	Items []Item
	Next  Cursor
	Done  bool
}

Page is one API response's worth of items plus the cursor to fetch the next. Set Done=true on the final page — Next is ignored when Done is true.

Jump to

Keyboard shortcuts

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