Skip to content

A Golang package that provides a simple retry mechanism

License

Notifications You must be signed in to change notification settings

TonyPath/retrier

Repository files navigation

Go Retrier

codecov Go Report Card go.mod Go version GoDoc

Simple retrier in Go

Examples

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