common

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultVal added in v0.0.35

func DefaultVal[T comparable](val, def T) T

func KeysFromItems added in v0.0.8

func KeysFromItems[T any](items *[]T, getKey func(T) int64) []int64

KeysFromItems returns the int64 keys from a response Items field.

Types

type BackoffConfig added in v0.0.9

type BackoffConfig struct {
	Strategy     BackoffStrategy `mapstructure:"strategy"`
	InitialDelay time.Duration   `mapstructure:"initial_delay"`
	MaxDelay     time.Duration   `mapstructure:"max_delay"`
	MaxRetries   int             `mapstructure:"max_retries"`
	Multiplier   float64         `mapstructure:"multiplier"` // Used for exponential backoff strategy
	Timeout      time.Duration   `mapstructure:"timeout"`
}

func (BackoffConfig) NextDelay added in v0.0.9

func (c BackoffConfig) NextDelay(prev time.Duration) time.Duration

func (BackoffConfig) Validate added in v0.0.9

func (c BackoffConfig) Validate() error

type BackoffStrategy added in v0.0.9

type BackoffStrategy string
const (
	BackoffFixed       BackoffStrategy = "fixed"
	BackoffExponential BackoffStrategy = "exponential"
)

type ResourceTypes

type ResourceTypes map[string]string

func (ResourceTypes) PrettyString

func (s ResourceTypes) PrettyString() string

func (ResourceTypes) String

func (s ResourceTypes) String() string

type Result added in v0.0.28

type Result[T any] struct {
	Index int // original position in the input slice
	Item  T
	Err   error
}

Result holds the outcome for one item.

func RunBulk added in v0.0.28

func RunBulk[T any](ctx context.Context, items []T, parallel int, fn WorkFunc[T]) []Result[T]

RunBulk runs fn over items with up to 'parallel' workers. - If parallel <= 0, it defaults to min(8, len(items)). - Results preserve input order (results[i] corresponds to items[i]). - Honors context cancellation; any not-yet-dispatched items are marked with ctx.Err().

type WorkFunc added in v0.0.28

type WorkFunc[T any] func(ctx context.Context, item T) error

WorkFunc is the per-item function you want to run.

Jump to

Keyboard shortcuts

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