retry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package retry owns replay safety, attempt lifetime, and retry sequencing. Callers supply policy and observations without transferring request ownership.

Index

Constants

View Source
const (
	// MaxRetryAfter is the fixed server-directed wait cap.
	MaxRetryAfter = 10 * time.Second
)

Variables

This section is empty.

Functions

func RoundTrip

func RoundTrip(req *http.Request, next http.RoundTripper, policy Policy) (*http.Response, error)

RoundTrip sends one logical request. Cancellation checks, policy callbacks, observations, cleanup, waits, and rewinds retain their distinct ordered phases.

Types

type Policy

type Policy struct {
	// Attempts includes the initial attempt.
	Attempts int
	// Backoff runs before Retry-After selection, even when the header stops retry.
	Backoff func(int) time.Duration
	// AttemptTimeout remains active until the returned body is closed.
	AttemptTimeout time.Duration
	// RetryIf classifies outcomes only after the caller-context guard.
	RetryIf func(*http.Response, error) bool
	// Failed observes terminal failures without consuming their response body.
	Failed func(context.Context, *http.Request, Result)
	// Retry observes a selected retry before response cleanup and waiting.
	Retry func(context.Context, *http.Request, Result, time.Duration)
}

Policy contains completed callbacks and attempt limits, not construction code.

type Result

type Result struct {
	// Number starts at one and includes rewind failures before native I/O.
	Number int
	// Response is returned unchanged on a terminal response; its body is owned
	// by the engine until it is returned or discarded before retrying.
	Response *http.Response
	// Err is the native transport error or contextual request-rewind error.
	Err error
}

Result retains one attempt's native outcome and identity for observations.

Jump to

Keyboard shortcuts

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