Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
Ensure keeps retring until ctx is done, it use a default retry object
Example ¶
r := New() ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() err := r.Ensure(ctx, func() error { resp, err := http.Get("http://www.example.com") // Get error can be retried if err != nil { log.Println(err) return Retriable(err) } log.Println(resp) buf := bytes.NewBuffer(nil) resp, err = http.Post("http://example.com/upload", "image/jpeg", buf) // Gost error should not be retried if err != nil { return err } log.Println(resp) return nil }) if err != nil { log.Fatal(err) }
Output:
Types ¶
type BackoffStrategy ¶
BackoffStrategy defines the backoff strategy of retry
func Exponential ¶
func Exponential(factor float64) BackoffStrategy
Exponential generates backoff duration by expoential
type Option ¶
type Option func(r *Retry)
Option is an option to new a Retry object
func WithBackoff ¶
func WithBackoff(backoff BackoffStrategy) Option
WithBackoff replace the default backoff function
func WithBaseDelay ¶
WithBaseDelay set the first delay duration, default 10ms
type RetriableErr ¶
type RetriableErr struct {
// contains filtered or unexported fields
}
RetriableErr is an error type which can be retried
Click to show internal directories.
Click to hide internal directories.