utils

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
const Infinitely = -1

Variables

View Source
var ErrMaxRetriesExceeded = errors.New("maximum number of retries exceeded")

Functions

func IdentityFunc

func IdentityFunc[T any]() func(T) T

func IgnoreError added in v0.5.0

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 added in v0.5.0

func IgnoreErrorWithOneArg[T any](fn func(t T) error, t T)

func IsNil added in v0.5.0

func IsNil[T any](value T) bool

func NewRetryRunner added in v0.8.0

func NewRetryRunner(logger logging2.Logger, maxTimes int, delay time.Duration, expBackoff bool) *retryRunner

func NewRetryRunnerWithJitter added in v0.12.1

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 Hashable added in v0.5.0

type Hashable []byte

func (Hashable) Raw added in v0.5.0

func (id Hashable) Raw() []byte

func (Hashable) RawString added in v0.5.0

func (id Hashable) RawString() string

func (Hashable) String added in v0.5.0

func (id Hashable) String() string

type Hasher added in v0.5.0

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

func NewSHA256Hasher added in v0.5.0

func NewSHA256Hasher() *Hasher

func (*Hasher) AddBool added in v0.5.0

func (h *Hasher) AddBool(b bool) (int, error)

func (*Hasher) AddBytes added in v0.5.0

func (h *Hasher) AddBytes(b []byte) error

func (*Hasher) AddFloat64 added in v0.5.0

func (h *Hasher) AddFloat64(f float64) error

func (*Hasher) AddG1s added in v0.5.0

func (h *Hasher) AddG1s(generators []*math.G1) error

func (*Hasher) AddInt added in v0.5.0

func (h *Hasher) AddInt(i int) error

func (*Hasher) AddInt32 added in v0.5.0

func (h *Hasher) AddInt32(i int32) error

func (*Hasher) AddString added in v0.5.0

func (h *Hasher) AddString(s string) error

func (*Hasher) AddUInt64 added in v0.5.0

func (h *Hasher) AddUInt64(i uint64) error

func (*Hasher) Digest added in v0.5.0

func (h *Hasher) Digest() []byte

func (*Hasher) HexDigest added in v0.5.0

func (h *Hasher) HexDigest() string

type RetryRunner added in v0.8.0

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.

Jump to

Keyboard shortcuts

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