paginate

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package paginate provides lazy and eager pagination for list operations that follow AIP-158.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[
	Item any,
	Resp Response[Item],
	Req Request[Req, Resp],
](request Req, opts ...Option) ([]Item, error)

All retrieves and returns all items yielded by Items. If pagination fails, All returns the items retrieved before the failure together with the error.

func Items

func Items[
	Item any,
	Resp Response[Item],
	Req Request[Req, Resp],
](request Req, opts ...Option) iter.Seq2[Item, error]

Items returns a lazy iterator over the items of pageable list operation. No request is made until the iterator is consumed. Each successful item is yielded with a nil error. If a request or option fails, the error is yielded once with the zero value of Item and iteration stops.

Iteration also stops when the consumer returns false, the configured item or page limit is reached, or the service returns an empty next page token.

Types

type Option

type Option func(*config) error

Option configures pagination behavior.

Options are applied sequentially in the order provided; if the same option is specified multiple times, the last one takes precedence.

func WithLimit

func WithLimit(limit int) Option

WithLimit sets the maximum number of items yielded across all pages. A zero limit performs no requests and yields no items.

func WithMaxPages

func WithMaxPages(maxPages int) Option

WithMaxPages sets the maximum number of pages fetched. A zero maximum performs no requests. Reaching the maximum is not an error.

func WithPageSize

func WithPageSize(pageSize int32) Option

WithPageSize sets the preferred number of items requested per page. The service may return fewer items. A value of zero does not override the page size already set on the supplied request.

type Request

type Request[Self, Resp any] interface {
	PageSize(pageSize int32) Self
	PageToken(pageToken string) Self
	Execute() (Resp, error)
}

Request defines the methods needed for pagination on the request side.

type Response

type Response[Item any] interface {
	GetItems() []Item
	GetNextPageToken() string
}

Response defines the methods needed for pagination. The result of Request.Execute() must implement this interface.

Jump to

Keyboard shortcuts

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