retry

package module
v0.0.0-...-7716d98 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 7 Imported by: 0

README

retry

Backoff retry with Idempotency-Key

var cont Content

bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 50 * time.Millisecond
bo.MaxInterval = 500 * time.Millisecond

err := hx.Get(ctx, "https://api.example.com/contents/1",
	retry.When(hx.Any(hx.IsServerError, hx.IsTemporaryError), bo),
	hx.WhenSuccess(hx.AsJSON(&cont)),
	hx.WhenFailure(hx.AsError()),
)

Documentation

Overview

A plugin for retry HTTP requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func When

func When(cond hx.ResponseHandlerCond, bo backoff.BackOff) hx.Option

When creates an option that provides retry mechanism for your http client.

bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 50 * time.Millisecond
bo.MaxInterval = 500 * time.Millisecond

err := hx.Post(ctx, "https://example.com/api/messages",
	retry.When(hx.Any(hx.IsServerError(), hx.IsTemporaryError()), bo),
	hx.JSON(&in),
	hx.WhenSuccess(hx.AsJSON(&out)),
	hx.WhenFailure(hx.AsError()),
)

Types

type Transport

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

func NewTransport

func NewTransport(
	parent http.RoundTripper,
	cond hx.ResponseHandlerCond,
	bo backoff.BackOff,
) *Transport

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

Jump to

Keyboard shortcuts

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