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 ¶
WithLimit sets the maximum number of items yielded across all pages. A zero limit performs no requests and yields no items.
func WithMaxPages ¶
WithMaxPages sets the maximum number of pages fetched. A zero maximum performs no requests. Reaching the maximum is not an error.
func WithPageSize ¶
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.