Percolate's Go retry package
ReTry is a simple Go package for implementing retry logic. It's partially based on the Python package, retry.
go get github.com/percolate/retry
It's easy! Configure an instance of Re
to your liking, and pass its Try
method a Func
of your choosing.
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)
}