https://github.com/percolate/retry
Percolate's Go retry package
https://github.com/percolate/retry
go retry
Last synced: 7 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 (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-16T18:34:48.000Z (over 2 years ago)
- Last Synced: 2025-03-29T06:23:17.063Z (8 months ago)
- Topics: go, retry
- Language: Shell
- Homepage:
- Size: 169 KB
- Stars: 10
- Watchers: 40
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - retry - | - | - | (Utilities / HTTP Clients)
- awesome-go-cn - retry
- awesome-go - retry - Percolate's Go retry package - ★ 2 (Utilities)
- awesome-go-plus - retry - A simple but highly configurable retry package for Go.  (Utilities / Utility/Miscellaneous)
- awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-cn - retry
- fucking-awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-zh - retry
- awesome-go - retry - A simple but highly configurable retry package for Go. - :arrow_down:0 - :star:2 (Utilities / HTTP Clients)
- awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-Char - retry - A simple but highly configurable retry package for Go. (Utilities / HTTP Clients)
- awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-extra - retry - 06-15T19:23:36Z|2019-09-05T21:13:28Z| (Utilities / Fail injection)
- awesome-go-with-stars - retry - A simple but highly configurable retry package for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-cn - retry
- awesome-go - retry - A simple but highly configurable retry package for Go. (Utilities / HTTP Clients)
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 main
import (
"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)
}
```