Simple retrier in Go
maxAttempts := 5
backoffInMillis := 1000
retrier, _ := NewPeriodicRetrier(maxAttempts, backoffInMillis)
res, err := retrier.Retry(
func() (any, error) {
res, err := http.Get(...)
return res, err
},
func(err error) bool {
var errDNS *net.DNSError
if errors.As(err, &errDNS) && errDNS.IsTemporary {
return true
}
return false
}
)