Documentation ¶
Overview ¶
Package retry implements a http.RoundTripper that retries requests
This package uses a configurable ExponentialBackoff mechanism:
r := retry.Transport { Backoff: backoff.NewExponentialBackoff(), ShouldRetry: /* optional custom retry check function */, Transport: /* chain transports! */, } client := http.Client{Transport: r} res, err := client.Do(http.NewRequest("GET", url, nil))
Example ¶
package main import ( "fmt" "net/http" "time" "github.com/tvastar/http/retry" "github.com/cenkalti/backoff" ) func main() { count := 0 r := retry.Transport{ Backoff: backoff.NewExponentialBackOff(), ShouldRetry: func(res *http.Response, err error, lastAttempt bool) (error, bool) { count++ return err, err != nil && !lastAttempt }, Transport: http.DefaultTransport, } r.Backoff.MaxElapsedTime = time.Second client := http.Client{Transport: r} req, err := http.NewRequest("GET", "x.boo.bohemian/a/b/c/d", nil) if err != nil { panic(err) } _, err = client.Do(req) fmt.Println("Got:", count, err == nil) }
Output: Got: 3 false
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.