Documentation
¶
Overview ¶
Package utils provides utility functions for resource cleanup and error handling. This file contains helpers for ignoring errors from cleanup operations like Close().
This file provides generic utility functions including identity functions and nil checking. IdentityFunc returns a function that returns its input unchanged. IsNil checks if a value is nil using reflection for pointer-like types.
This file provides utilities for computing SHA256 hashes. Hashable is a byte slice that can compute its own hash. Hasher provides a builder pattern for incrementally constructing hashes from various data types.
This file provides retry logic with exponential backoff and context cancellation support. RetryRunner executes functions with configurable retry strategies, supporting both fixed and exponential backoff delays with a maximum delay cap.
Index ¶
- Constants
- Variables
- func IdentityFunc[T any]() func(T) T
- func IgnoreError(fn func() error)
- func IgnoreErrorWithOneArg[T any](fn func(t T) error, t T)
- func IsNil[T any](value T) bool
- func NewRetryRunner(logger logging2.Logger, maxTimes int, delay time.Duration, expBackoff bool) *retryRunner
- func NewRetryRunnerWithJitter(logger logging2.Logger, maxTimes int, initialDelay, maxDelay time.Duration, ...) *retryRunner
- type Hashable
- type Hasher
- func (h *Hasher) AddBool(b bool) (int, error)
- func (h *Hasher) AddBytes(b []byte) error
- func (h *Hasher) AddFloat64(f float64) error
- func (h *Hasher) AddG1s(generators []*math.G1) error
- func (h *Hasher) AddInt(i int) error
- func (h *Hasher) AddInt32(i int32) error
- func (h *Hasher) AddString(s string) error
- func (h *Hasher) AddUInt64(i uint64) error
- func (h *Hasher) Digest() []byte
- func (h *Hasher) HexDigest() string
- type RetryRunner
Constants ¶
const Infinitely = -1
Variables ¶
var ErrMaxRetriesExceeded = errors.New("maximum number of retries exceeded")
Functions ¶
func IdentityFunc ¶
func IdentityFunc[T any]() func(T) T
func IgnoreError ¶
func IgnoreError(fn func() error)
IgnoreError runs a function that returns an error and silently ignores the error. It is intended to be used when the error from a cleanup operation (e.g., Close) is non-critical and can be safely discarded.
Example:
defer IgnoreError(file.Close)
func IgnoreErrorWithOneArg ¶
func NewRetryRunner ¶
func NewRetryRunnerWithJitter ¶
func NewRetryRunnerWithJitter(logger logging2.Logger, maxTimes int, initialDelay, maxDelay time.Duration, backoffMultiplier, jitterFactor float64) *retryRunner
NewRetryRunnerWithJitter creates a retry runner with configurable jitter and backoff multiplier. jitterFactor should be between 0.0 and 1.0, where 0.0 means no jitter and 1.0 means maximum jitter. backoffMultiplier controls the exponential growth rate (e.g., 2.0 doubles the delay each time).
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
func NewSHA256Hasher ¶
func NewSHA256Hasher() *Hasher
func (*Hasher) AddFloat64 ¶
type RetryRunner ¶
type RetryRunner interface {
Run(func() error) error
// RunWithContext retries like Run but stops early if ctx is canceled.
RunWithContext(ctx context.Context, runner func() error) error
// RunWithErrors retries until runner returns true or maxTimes is exhausted.
RunWithErrors(runner func() (bool, error)) error
// RunWithErrorsContext retries like RunWithErrors but stops early if ctx is canceled.
RunWithErrorsContext(ctx context.Context, runner func() (bool, error)) error
}
RetryRunner receives a function that potentially fails and retries according to the specified strategy
Directories
¶
| Path | Synopsis |
|---|---|
|
This file implements a no-op cache that always misses and never stores values.
|
This file implements a no-op cache that always misses and never stores values. |
|
This file implements a generic, thread-safe registry for storing and retrieving drivers by key.
|
This file implements a generic, thread-safe registry for storing and retrieving drivers by key. |
|
This file provides JSON unmarshaling with strict validation.
|
This file provides JSON unmarshaling with strict validation. |
|
This file provides utilities for converting between domain objects and protobuf messages.
|
This file provides utilities for converting between domain objects and protobuf messages. |
|
mock
Code generated by counterfeiter.
|
Code generated by counterfeiter. |
|
This file provides generic slice utility functions.
|
This file provides generic slice utility functions. |
|
types
|
|
|
This file provides utilities for running views with timeout support.
|
This file provides utilities for running views with timeout support. |