util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: GPL-3.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(attempts int, delay time.Duration, fn func() error) error

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic writes data to path atomically: the content goes to a temp file in the same directory first, then is renamed over the destination, so a crash mid-write can never leave a half-written file behind for the next reader to parse.

Types

type Backoff

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

Backoff produces exponentially increasing delays with full jitter, for retry loops that must not hammer a failing server. The zero value is not usable; construct with NewBackoff.

func NewBackoff

func NewBackoff(initial, max time.Duration) *Backoff

NewBackoff returns a Backoff that starts at initial and doubles on every Next call, capped at max.

func (*Backoff) Next

func (b *Backoff) Next() time.Duration

Next returns the next delay, with full jitter applied (a uniform random value between 0 and the current step), then advances the sequence.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset restarts the sequence from the initial delay. Call it when a retry loop finally succeeds, so the next failure starts fast again instead of inheriting a long-grown delay.

Jump to

Keyboard shortcuts

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