Help us shape the future of Go! Take the 2026 Go Developer Survey

serverlesshttp

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package serverlesshttp provides an http.RoundTripper that retries 429 Too Many Requests responses from the Elastic Cloud Serverless API.

Only 429 is retried. The Serverless API does not document a Retry-After header, so retries use self-paced exponential backoff with jitter. All other responses (including 5xx) are returned to the caller untouched, which avoids any idempotency concerns around retrying write methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*RetryTransport)

Option configures a RetryTransport.

func WithBaseBackoff

func WithBaseBackoff(d time.Duration) Option

WithBaseBackoff sets the initial backoff duration.

func WithMaxAttempts

func WithMaxAttempts(n int) Option

WithMaxAttempts sets the total number of attempts including the first.

func WithMaxBackoff

func WithMaxBackoff(d time.Duration) Option

WithMaxBackoff caps the backoff duration.

func WithNext

func WithNext(next http.RoundTripper) Option

WithNext sets the underlying transport.

type RetryTransport

type RetryTransport struct {
	// Next is the underlying transport. Defaults to http.DefaultTransport.
	Next http.RoundTripper

	// MaxAttempts is the total number of attempts including the first. A
	// value of 1 disables retries. Defaults to 5.
	MaxAttempts int

	// BaseBackoff is the initial backoff duration. Defaults to 1 second.
	BaseBackoff time.Duration

	// MaxBackoff caps the backoff duration. Defaults to 30 seconds.
	MaxBackoff time.Duration
}

RetryTransport retries 429 Too Many Requests responses with bounded exponential backoff and jitter.

func New

func New(opts ...Option) *RetryTransport

New returns a RetryTransport wrapping the given transport (or http.DefaultTransport if next is nil) with sensible defaults.

func (*RetryTransport) RoundTrip

func (t *RetryTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes the request, retrying 429 responses up to MaxAttempts times with exponential backoff and jitter.

Jump to

Keyboard shortcuts

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