util

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesFromShortString

func BytesFromShortString(s string) []byte

func BytesFromTime

func BytesFromTime(t time.Time) []byte

func BytesFromUint32

func BytesFromUint32(v uint32) []byte

func BytesFromUint64

func BytesFromUint64(v uint64) []byte

func IsNetworkError

func IsNetworkError(err error) bool

IsNetworkError returns true if the error appears to be a network error

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError combines common retry conditions

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError returns true if the error appears to be temporary

func NewGRPCClient added in v0.3.1

func NewGRPCClient(address string) (*grpc.ClientConn, error)

func ParseSizeString

func ParseSizeString(sizeStr string) (int, error)

parseSizeString converts a size string (e.g., "1.5MB", "1024KB") to bytes.

func Retry

func Retry(ctx context.Context, config RetryConfig, operation func() error) error

Retry executes the given function with exponential backoff retry

func RetryWithResult

func RetryWithResult[T any](ctx context.Context, config RetryConfig, operation func() (T, error)) (T, error)

RetryWithResult executes the given function with exponential backoff retry and returns the result

func ShortStringFromBytes

func ShortStringFromBytes(b []byte) string

func Uint32FromBytes

func Uint32FromBytes(b []byte) uint32

func Uint64FromBytes

func Uint64FromBytes(b []byte) uint64

Types

type RetryConfig

type RetryConfig struct {
	// MaxAttempts is the maximum number of retry attempts
	MaxAttempts int
	// InitialBackoff is the initial backoff duration
	InitialBackoff time.Duration
	// MaxBackoff is the maximum backoff duration
	MaxBackoff time.Duration
	// BackoffFactor is the factor by which the backoff increases
	BackoffFactor float64
	// RetryableErrors is a function that determines if an error is retryable
	RetryableErrors func(error) bool
}

RetryConfig holds the configuration for retry operations

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns a default retry configuration

Jump to

Keyboard shortcuts

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