iterator

package
v2.51.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[Req PageRequest, T any] struct {
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator[Req PageRequest, T any](
	ctx context.Context,
	req Req,
	fetch PageFetcher[Req, T],
	opts ...grpc.CallOption,
) *Iterator[Req, T]

func (*Iterator[Req, T]) Error

func (it *Iterator[Req, T]) Error() error

func (*Iterator[Req, T]) Next

func (it *Iterator[Req, T]) Next() bool

func (*Iterator[Req, T]) NextPageToken

func (it *Iterator[Req, T]) NextPageToken() string

func (*Iterator[Req, T]) Take

func (it *Iterator[Req, T]) Take(size int64) ([]T, error)

func (*Iterator[Req, T]) TakeAll

func (it *Iterator[Req, T]) TakeAll() ([]T, error)

func (*Iterator[Req, T]) Value

func (it *Iterator[Req, T]) Value() T

type PageFetcher

type PageFetcher[Req PageRequest, T any] func(
	ctx context.Context,
	req Req,
	opts ...grpc.CallOption,
) (PageResponse[T], error)

type PageRequest

type PageRequest interface {
	GetPageSize() int64
	SetPageSize(int64)
	GetPageToken() string
	SetPageToken(string)
}

type PageResponse

type PageResponse[T any] interface {
	Items() []T
	GetNextPageToken() string
}

type SimpleFetcher added in v2.45.0

type SimpleFetcher[Req any, T any] func(
	ctx context.Context,
	req Req,
	opts ...grpc.CallOption,
) (SimpleResponse[T], error)

SimpleFetcher is the function type that fetches all items in a single request.

type SimpleIterator added in v2.45.0

type SimpleIterator[Req any, T any] struct {
	// contains filtered or unexported fields
}

SimpleIterator iterates over items from a non-paginated List method. Unlike Iterator, it fetches all items in a single request.

func NewSimpleIterator added in v2.45.0

func NewSimpleIterator[Req any, T any](
	ctx context.Context,
	req Req,
	fetch SimpleFetcher[Req, T],
	opts ...grpc.CallOption,
) *SimpleIterator[Req, T]

NewSimpleIterator creates a new iterator for non-paginated responses.

func (*SimpleIterator[Req, T]) Error added in v2.45.0

func (it *SimpleIterator[Req, T]) Error() error

Error returns the error that occurred during iteration, if any.

func (*SimpleIterator[Req, T]) Next added in v2.45.0

func (it *SimpleIterator[Req, T]) Next() bool

Next advances the iterator to the next item. Returns true if there is an item available, false otherwise.

func (*SimpleIterator[Req, T]) Take added in v2.45.0

func (it *SimpleIterator[Req, T]) Take(size int64) ([]T, error)

Take returns up to size items from the iterator. If size is 0, returns all items.

func (*SimpleIterator[Req, T]) TakeAll added in v2.45.0

func (it *SimpleIterator[Req, T]) TakeAll() ([]T, error)

TakeAll returns all items from the iterator.

func (*SimpleIterator[Req, T]) Value added in v2.45.0

func (it *SimpleIterator[Req, T]) Value() T

Value returns the current item. Panics if called on an empty iterator.

type SimpleResponse added in v2.45.0

type SimpleResponse[T any] interface {
	Items() []T
}

SimpleResponse is the interface for responses that contain a list of items but don't use pagination (return all items in a single response).

Jump to

Keyboard shortcuts

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