The retryhttp package is HTTP client with configurable retry policy.
The retryhttp package is identical to what you would do with
net/http. Example:
resp, err := retryhttp.Get("/foo")
if err != nil {
panic(err)
}Also was added additional methods Do2Bytes and Do2JSON. Example:
var response struct{
IP string
}
request, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://ip.jsontest.com", nil)
err = retryhttp.Do2JSON(request, &response)
if err != nil {
panic(err)
}
fmt.Println("You ip", response.IP)User can override retry policy for client:
prop := func(properties *Properties) {
properties.Attempts = 10
properties.Timeout = time.Second
}
client := New(prop)User can register choice of JSON library into retryhttp or write own. By default retryhttp registers standard encoding/json respectively.
import "github.com/goccy/go-json"
prop := func(properties *Properties) {
properties.JSONUnmarshal = json.Unmarshal
}
client := New(prop)