clientutils

package
v0.0.0-...-0097dfa Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectWithFallback

func CollectWithFallback[T any](ctx context.Context,
	pageFunc func(context.Context, int, string) ([]T, string, error),
	fallbackFunc func(context.Context) ([]T, error)) ([]T, error)

CollectWithFallback collects all items in a collection using pageFunc, should the this be NotImplemented a fallbackFunc is attempted. Example:

foos, err := clientutils.CollectWithFallback(ctx, client.ListFoos, client.GetFoos)

func IterateResources

func IterateResources[T any](
	ctx context.Context,
	pageFunc func(context.Context, int, string) ([]T, string, error),
	callback func(T) error,
) error

IterateResources is a helper that iterates through each resource from all pages and passes them one by one to the provided callback. Deprecated: Prefer using Resources instead. TODO(tross): DELETE IN 19.0.0

func Page

func Page[T any](
	ctx context.Context,
	pageSize int,
	pageToken string,
	pageFunc func(context.Context, int, string) ([]T, string, error),
) (
	_ []T,
	nextPageToken string,
	lastPageSize int,
	_ error,
)

Page is a client side utility which implements auto page size adjustment.

func RangeResources

func RangeResources[T any](ctx context.Context, start, end string,
	pageFunc func(context.Context, int, string) ([]T, string, error),
	keyFunc func(item T) string) iter.Seq2[T, error]

RangeResources returns resources within the range [start, end).

Example use:

func (c *Client) RangeFoos(ctx context.Context, start, end string) iter.Seq2[Foo, error] {
	return clientutils.RangeResources(ctx, start, end, c.ListFoos, Foo.GetName)
}

func Resources

func Resources[T any](ctx context.Context, pageFunc func(context.Context, int, string) ([]T, string, error)) iter.Seq2[T, error]

Resources returns an iterator over all resources from every page produced from the pageFunc. The iterator will only produce an error if one is encountered retrieving a page.

func ResourcesWithPageSize

func ResourcesWithPageSize[T any](ctx context.Context, pageFunc func(context.Context, int, string) ([]T, string, error), pageSize int) iter.Seq2[T, error]

ResourcesWithPageSize returns an iterator over all resources from every page, limited to pageSize, produced from the pageFunc. The iterator will only produce an error if one is encountered retrieving a page.

Types

This section is empty.

Jump to

Keyboard shortcuts

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