Skip to content

Repository files navigation

ReTry

circlecicodecov

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.

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

package main
import (
"fmt""io/ioutil""net/http""time""github.com/percolate/retry"
)
funcmain() {
url:="http://example.com"delay:=time.Duration(10*time.Millisecond)
varbody []byteerr:= retry.Re{Max: 3, Delay: delay}.Try(func() error {
resp, err:=http.Get(url)
iferr!=nil {
returnerr
}
deferresp.Body.Close()
body, err=ioutil.ReadAll(resp.Body)
iferr!=nil {
returnerr
}
returnnil
})
iferr!=nil {
fmt.Println(err)
}
fmt.Println(body)
}

About

Percolate's Go retry package

Topics

Resources

Stars

11 stars

Watchers

38 watching

Forks

Releases

Packages

Used by

Contributors

Languages