https://github.com/percolate/retry
Percolate's Go retry package
https://github.com/percolate/retry
go retry
Last synced: 4 months ago
JSON representation
Percolate's Go retry package
- Host: GitHub
- URL: https://github.com/percolate/retry
- Owner: percolate
- License: bsd-3-clause
- Created: 2018-06-15T19:23:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-16T18:34:48.000Z (about 2 years ago)
- Last Synced: 2024-11-16T23:32:33.900Z (5 months ago)
- Topics: go, retry
- Language: Shell
- Homepage:
- Size: 169 KB
- Stars: 10
- Watchers: 42
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - retry - Percolate's Go retry package - ★ 2 (Utilities)
- awesome-go-extra - retry - 06-15T19:23:36Z|2019-09-05T21:13:28Z| (Utilities / Fail injection)
README
# ReTry
[](https://circleci.com/gh/percolate/retry)
[](https://codecov.io/gh/percolate/retry)Percolate's Go retry package
## Description
ReTry is a simple Go package for implementing retry logic. It's partially based
on the Python package, [retry](https://github.com/invl/retry).## Installation
`go get github.com/percolate/retry`
## Usage
It's easy! Configure an instance of `Re` to your liking, and pass its `Try`
method a `Func` of your choosing.## Example
```go
package mainimport (
"fmt"
"io/ioutil"
"net/http"
"time""github.com/percolate/retry"
)func main() {
url := "http://example.com"
delay := time.Duration(10*time.Millisecond)var body []byte
err := retry.Re{Max: 3, Delay: delay}.Try(func() error {
resp, err := http.Get(url)
if err != nil {
return err
}defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return err
}return nil
})if err != nil {
fmt.Println(err)
}
fmt.Println(body)
}
```