A simple Go (Golang) library for retries featuring generics. Backoff is configurable. The most useful is probably exponential backoff with full jitter.
For usage see the godoc.
body, err := retrier.DoWithData(func() ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
}, retrier.NewExponentialBackoff())
err := retrier.Do(func() error {
// db of type *sql.DB
if err = db.PingContext(context.Background()); err != nil {
return err
}
return nil
}, retrier.NewExponentialBackOff())
if err != nil {
return nil, fmt.Errorf("error pinging the db: %w", err)
}
Contributions are welcome! Please create an issue for significant changes.