utils

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 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

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 IgnoreErrorWithOneArg[T any](fn func(t T) error, t T)

func IsNil

func IsNil[T any](value T) bool

func NewRetryRunner

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

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 Hashable

type Hashable []byte

func (Hashable) Raw

func (id Hashable) Raw() []byte

func (Hashable) RawString

func (id Hashable) RawString() string

func (Hashable) String

func (id Hashable) String() string

type Hasher

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

func NewSHA256Hasher

func NewSHA256Hasher() *Hasher

func (*Hasher) AddBool

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

func (*Hasher) AddBytes

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

func (*Hasher) AddFloat64

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

func (*Hasher) AddG1s

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

func (*Hasher) AddInt

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

func (*Hasher) AddInt32

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

func (*Hasher) AddString

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

func (*Hasher) AddUInt64

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

func (*Hasher) Digest

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

func (*Hasher) HexDigest

func (h *Hasher) HexDigest() string

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.

Jump to

Keyboard shortcuts

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