https://github.com/pthethanh/retry
retry is a simple http-retry client that support backoff policy such as exponential backoff with max retries...
https://github.com/pthethanh/retry
backoff go golang http-client http-retry retry
Last synced: 2 months ago
JSON representation
retry is a simple http-retry client that support backoff policy such as exponential backoff with max retries...
- Host: GitHub
- URL: https://github.com/pthethanh/retry
- Owner: pthethanh
- License: mit
- Created: 2018-11-24T09:32:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-25T08:35:43.000Z (over 7 years ago)
- Last Synced: 2025-01-01T02:42:51.395Z (over 1 year ago)
- Topics: backoff, go, golang, http-client, http-retry, retry
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# retry
retry is a simple http-retry client that support backoff policy such as exponential backoff with max retries...
```
# retry
go get github.com/golovers/retry
# dependencies
go get github.com/cenkalti/backoff
go get github.com/sirupsen/logrus
```
## Usage
```go
c := retry.New()
req, _ := http.NewRequest(http.MethodGet, "https://www.github.com/pthethanh", nil)
// Using default backoff policy and default retry func
rs, err := c.Do(req)
logrus.Infof("response: %+v, err: %v", rs, err)
// Using custom backoff policy
rs, err = c.DoWithBackOff(req, backoff.NewExponentialBackOff())
logrus.Infof("response: %+v, err: %v", rs, err)
// Using custom backoff policy and custom retry func
rs, err = c.DoWithRetryFunc(req, backoff.NewConstantBackOff(1*time.Second), func(rs *http.Response) bool {
return rs.StatusCode == http.StatusInternalServerError
})
logrus.Infof("response: %+v, err: %v", rs, err)
```