https://github.com/phachon/retry
a retry go package
https://github.com/phachon/retry
golang retry
Last synced: 11 months ago
JSON representation
a retry go package
- Host: GitHub
- URL: https://github.com/phachon/retry
- Owner: phachon
- License: mit
- Created: 2019-03-04T09:11:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-04T10:01:19.000Z (over 7 years ago)
- Last Synced: 2025-01-20T02:53:11.904Z (over 1 year ago)
- Topics: golang, retry
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/phachon/retry/)
[](https://travis-ci.org/phachon/retry)
[](https://godoc.org/github.com/phachon/retry)
[](https://raw.githubusercontent.com/phachon/retry/master/LICENSE)
[](https://goreportcard.com/report/github.com/phachon/retry)
[]()
Have a good retry.
[中文文档](README_CN.md)
## Feature
- Support setting retry times
- Support setting retry interval
- Support setting retry timeout
## Install
```bash
go get github.com/phachon/retry
```
## Used
```go
import github.com/phachon/retry
```
### Simple
```go
url := "https://api.github.com/"
req, _ := http.NewRequest("GET", url, nil)
var res *http.Response
err := retry.Retry(func() (err error) {
res, err = http.DefaultClient.Do(req)
if err != nil {
return err
}
return nil
}, retry.SetRetryCount(2))
if err != nil {
painc(err)
}
body, _ := ioutil.ReadAll(res.Body)
defer res.Body.Close()
fmt.Println(string(body))
```
### Retry interval
```go
url := "https://api.github.com/"
req, _ := http.NewRequest("GET", url, nil)
var res *http.Response
err := retry.Retry(func() (err error) {
res, err = http.DefaultClient.Do(req)
if err != nil {
return err
}
return nil
}, retry.SetRetryCount(3), retry.SetIntervalTime(3 * time.Second))
if err != nil {
panic(err)
}
body, _ := ioutil.ReadAll(res.Body)
defer res.Body.Close()
fmt.Println(string(body))
```
### Retry timeout
```go
url := "https://api.github.com/"
req, _ := http.NewRequest("GET", url, nil)
var res *http.Response
err := retry.Retry(func() (err error) {
res, err = http.DefaultClient.Do(req)
if err != nil {
return err
}
return nil
}, retry.SetRetryCount(3), retry.SetRetryTimeout(800 * time.Millisecond))
if err != nil {
panic(err)
return
}
body, _ := ioutil.ReadAll(res.Body)
defer res.Body.Close()
fmt.Println(string(body))
```
## Feedback
- If you like the project, please [Star](https://github.com/phachon/retry/stargazers).
- If you have any problems in the process of use, welcome submit [Issue](https://github.com/phachon/retry/issues).
- If you find and solve bug, welcome submit [Pull Request](https://github.com/phachon/retry/pulls).
- If you want to redevelop, welcome [Fork](https://github.com/phachon/retry/network/members).
- If you want to make a friend, welcome send email to [phachon@163.com](mailto:phachon@163.com).
## License
MIT
Thanks
---------
Create By phachon@163.com