common

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultItemConcurrency = 8

DefaultItemConcurrency bounds per-item AWS describe fan-out (distinct from the user-facing --max-concurrency, which bounds multi-region fan-out).

Variables

View Source
var DefaultRetryConfig = RetryConfig{
	MaxAttempts:       5,
	InitialBackoff:    200 * time.Millisecond,
	MaxBackoff:        5 * time.Second,
	BackoffMultiplier: 2.0,
}

Functions

func ForEachParallel added in v0.7.0

func ForEachParallel[T, R any](ctx context.Context, items []T, maxConcurrency int, fn func(ctx context.Context, item T) R) []R

ForEachParallel runs fn over items with bounded concurrency and returns the results in input order. fn must be safe to call concurrently; per-item failures should be encoded in R (e.g. a nil pointer) rather than aborting the whole batch, matching the best-effort semantics of list operations.

func IdempotencyToken added in v0.7.0

func IdempotencyToken() string

IdempotencyToken returns a random token for AWS APIs that accept a ClientRequestToken. Setting it explicitly ONCE per logical operation lets retry wrappers re-issue the request without risking a double-apply (the SDK only auto-fills a fresh token per call, which defeats idempotency across caller-level retries).

func Paginate added in v0.6.0

func Paginate[Item any](
	ctx context.Context,
	fetch func(ctx context.Context, token *string) (items []Item, next *string, err error),
) ([]Item, error)

Paginate calls fetch with the previous response's next token until the returned token is nil or empty. Returned items from each page are appended in order. fetch is responsible for any per-page retry/error formatting.

func WithRetry

func WithRetry[T any](ctx context.Context, cfg RetryConfig, fn func(context.Context) (T, error)) (T, error)

WithRetry runs fn with exponential backoff respecting context cancellation.

Types

type RetryConfig

type RetryConfig struct {
	MaxAttempts       int
	InitialBackoff    time.Duration
	MaxBackoff        time.Duration
	BackoffMultiplier float64
}

RetryConfig controls retry behavior for AWS API calls.

type TTLCache added in v0.7.0

type TTLCache struct {
	// contains filtered or unexported fields
}

TTLCache is a thread-safe in-memory cache with per-entry TTLs. Expired entries are deleted lazily on Get — a short-lived CLI process doesn't need a background janitor goroutine. It is the single cache implementation shared by the service packages (cluster and nodegroup previously kept near-identical copies).

func NewTTLCache added in v0.7.0

func NewTTLCache(defaultTTL time.Duration) *TTLCache

NewTTLCache creates a cache. defaultTTL is used by SetDefault; pass 0 if every Set call provides its own TTL.

func (*TTLCache) Clear added in v0.7.0

func (c *TTLCache) Clear()

Clear removes all items from the cache.

func (*TTLCache) Delete added in v0.7.0

func (c *TTLCache) Delete(key string)

Delete removes a value from the cache.

func (*TTLCache) Get added in v0.7.0

func (c *TTLCache) Get(key string) (any, bool)

Get retrieves a value from the cache, lazily deleting expired entries.

func (*TTLCache) Set added in v0.7.0

func (c *TTLCache) Set(key string, value any, ttl time.Duration)

Set stores a value with the given TTL.

func (*TTLCache) SetDefault added in v0.7.0

func (c *TTLCache) SetDefault(key string, value any)

SetDefault stores a value with the cache's default TTL.

func (*TTLCache) Stats added in v0.7.0

func (c *TTLCache) Stats() map[string]any

Stats returns cache statistics.

Jump to

Keyboard shortcuts

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