httpclient

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneHeader

func CloneHeader(headers http.Header) http.Header

func CloneValues

func CloneValues(values url.Values) url.Values

func CloseResponse

func CloseResponse(resp *http.Response)

func DecodeJSON

func DecodeJSON(resp *http.Response, body []byte, provider string, out any) error

func EnsureLeadingSlash

func EnsureLeadingSlash(path string) string

func Execute

func Execute(
	ctx context.Context,
	client *http.Client,
	retry RetryPolicy,
	template *http.Request,
	idempotent bool,
) (*http.Response, []byte, error)

func JoinPath

func JoinPath(parts ...string) string

func ParseRetryAfter

func ParseRetryAfter(value string, now time.Time) (time.Duration, bool)

func SleepWithContext

func SleepWithContext(ctx context.Context, d time.Duration) error

func SnapshotBody

func SnapshotBody(resp *http.Response) ([]byte, error)

Types

type RetryClassifier

type RetryClassifier func(policy RetryPolicy, resp *http.Response, err error, attempt int) RetryDecision

type RetryDecision

type RetryDecision struct {
	Retry bool
	Delay time.Duration
	Err   error
}

func DefaultRetryClassifier

func DefaultRetryClassifier(policy RetryPolicy, resp *http.Response, err error, attempt int) RetryDecision

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
	Sleep       func(context.Context, time.Duration) error
	Rand        func() float64
	Clock       func() time.Time
	Classifier  RetryClassifier
}

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

func (RetryPolicy) Do

func (p RetryPolicy) Do(ctx context.Context, idempotent bool, fn func() (*http.Response, error)) (*http.Response, error)

func (RetryPolicy) ExponentialBackoff

func (p RetryPolicy) ExponentialBackoff(attempt int) time.Duration

func (RetryPolicy) JitterBackoff

func (p RetryPolicy) JitterBackoff(attempt int) time.Duration

func (RetryPolicy) Now

func (p RetryPolicy) Now() time.Time

Jump to

Keyboard shortcuts

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