Retrigo is a very striped down version of the hashicorp/go-retryablehttp, it implements the familiar HTTP package with automatic retries and backoff method.
Using default client
c := retrigo.NewClient()
resp, err := c.Post("http://localhost", "text/plain", bytes.NewReader([]byte{}))
...
Setting all parameters
c := retrigo.Client{
HTTPClient: &http.Client{
Timeout: 10 * time.Second,
},
Logger: retrigo.DefaultLogger,
RetryWaitMin: 20 * time.Millisecond,
RetryWaitMax: 10 * time.Second,
RetryMax: 5,
CheckForRetry: retrigo.DefaultRetryPolicy,
Backoff: retrigo.DefaultBackoff,
Scheduler: retrigo.DefaultScheduler,
}
resp, err := c.Get("http://localhost")
...
Setting some parameters
c := retrigo.NewClient()
c.RetryWaitMin = 20 * time.Millisecond
c.RetryWaitMax = 10 * time.Second
c.Backoff = retrigo.LinearJitterBackoff
resp, err := c.Get("http://localhost")
...
Without creating a client
resp, err := retrigo.Get("http://localhost")
...
The url parameter (e. g., c.Get("URL")
) can be one url or a space separated list of urls that the library will choose as target (e. g., "URL1 URL2 URL3"
). The default Scheduler() will round-robin around all urls of the list, you can implement other scheduling strategies by defining your own Scheduler() e.g.:
c := retrigo.NewClient()
c.Scheduler = func(servers []string, j int) (string, int) {
...
}
The Logger() function defines the logging methods/format, this function will receive a severity, a message and a error struct.