This project provide utilities to retry fallible function calls
To install, use go get
go get github.com/IQ-tech/go-retry
// We will attempt the function call 3 times
// with an initial waiting time of 3 seconds.
retryOptions := retry.Options{
Attempts: 3,
InitialTimeBetweenRetries: 3,
}
value, err = retry.Func(retryOptions, func() (interface{}, error) {
return someservice.GetSomeValue()
})
// [err] will be non nil if the function didn't succeed after
// the maximum number of attempts has been reached.
if err != nil {
panic(err)
}
fmt.Println(value)