Skip to content
Percolate's Go retry package
Branch: master
Clone or download
lra Merge pull request #2 from percolate/lra-patch-1
Update any use of a docker-hub container to use ECR
Latest commit 7f9c39c Jun 25, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
sbin
vendor/github.com
.gitignore
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
VERSION.txt
codecov.yml
retry.go
retry_test.go

README.md

ReTry

circleci codecov

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"
)

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)
}
You can’t perform that action at this time.