Skip to content

wolviecb/retrigo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retrigo - Very simple http retriable client

License: MPL 2.0 GoDoc Build Status codecov Go Report Card

Retrigo is a very striped down version of the hashicorp/go-retryablehttp, it implements the familiar HTTP package with automatic retries and backoff method.

Usage

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")
...

Multiple targets

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

Logging

The Logger() function defines the logging methods/format, this function will receive a severity, a message and a error struct.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages