retry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package retry implements simple retry functionality.

For example to retry an HTTP request:

func Do(client *http.Client, req *http.Request) (rsp *http.Response, err error) {
    retry.Retry(
        retry.Count(5),
        retry.Backoff(time.Second, time.Second*30),
        func(i int) bool {
            if 0 < i {
                req.Body, err = req.GetBody()
                if nil != err {
                    return false
                }
            }
            rsp, err = client.Do(req)
            if nil != err {
                return false
            }
            if 500 <= rsp.StatusCode && nil != req.GetBody {
                rsp.Body.Close()
                return true
            }
            return false
        })

    return
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backoff

func Backoff(sleep, maxsleep time.Duration) func(int) bool

Backoff implements an exponential backoff with jitter.

func Count

func Count(retries int) func(int) bool

Count limits the number of retries performed by Retry.

func Retry

func Retry(actions ...func(int) bool)

Retry performs actions repeatedly until one of the actions returns false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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