Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shafreeck/retry
A pretty simple library to ensure your work to be done
https://github.com/shafreeck/retry
go golang retry retry-library retrying timeout
Last synced: about 2 months ago
JSON representation
A pretty simple library to ensure your work to be done
- Host: GitHub
- URL: https://github.com/shafreeck/retry
- Owner: shafreeck
- License: apache-2.0
- Created: 2018-07-18T09:48:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-11T03:47:03.000Z (almost 5 years ago)
- Last Synced: 2024-08-03T15:06:09.929Z (5 months ago)
- Topics: go, golang, retry, retry-library, retrying, timeout
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - retry - A pretty simple library to ensure your work to be done - ★ 7 (Utilities)
- awesome-go-extra - retry - 07-18T09:48:33Z|2020-02-11T03:47:03Z| (Utilities / Fail injection)
README
Retry is a pretty simple library to ensure your work to be done
[godoc](https://godoc.org/github.com/shafreeck/retry)
[![Go Report Card](https://goreportcard.com/badge/github.com/shafreeck/retry)](https://goreportcard.com/report/github.com/shafreeck/retry)
[![cover.run](https://cover.run/go/github.com/shafreeck/retry.svg?style=flat&tag=golang-1.9)](https://cover.run/go?tag=golang-1.9&repo=github.com%2Fshafreeck%2Fretry)## Features
* Retry to run a workflow(Ex. rpc or db access)
* Customize backoff strategy
* Retry accoding to your type of error## Examples
```go
func ExampleEnsure() {
r := New()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()err := r.Ensure(ctx, func() error {
resp, err := http.Get("http://www.example.com")
// Get error can be retried
if err != nil {
log.Println(err)
return Retriable(err)
}
log.Println(resp)buf := bytes.NewBuffer(nil)
resp, err = http.Post("http://example.com/upload", "image/jpeg", buf)
// Post error should not be retried
if err != nil {
return err
}
log.Println(resp)
return nil
})
if err != nil {
log.Fatal(err)
}
}
```