MCPcopy
hub / github.com/hashicorp/go-retryablehttp

github.com/hashicorp/go-retryablehttp @v0.7.8 sqlite

repository ↗ · DeepWiki ↗ · release v0.7.8 ↗
97 symbols 351 edges 6 files 46 documented · 47%
README

go-retryablehttp

Build Status Go Documentation

The retryablehttp package provides a familiar HTTP client interface with automatic retries and exponential backoff. It is a thin wrapper over the standard net/http client library and exposes nearly the same public API. This makes retryablehttp very easy to drop into existing programs.

retryablehttp performs automatic retries under certain conditions. Mainly, if an error is returned by the client (connection errors, etc.), or if a 500-range response code is received (except 501), then a retry is invoked after a wait period. Otherwise, the response is returned and left to the caller to interpret.

The main difference from net/http is that requests which take a request body (POST/PUT et. al) can have the body provided in a number of ways (some more or less efficient) that allow "rewinding" the request body if the initial request fails so that the full request can be attempted again. See the godoc for more details.

Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required. From 0.6.7 onward, Go 1.13+ is required.

Example Use

Using this library should look almost identical to what you would do with net/http. The most simple example of a GET request is shown below:

resp, err := retryablehttp.Get("/foo")
if err != nil {
    panic(err)
}

The returned response object is an *http.Response, the same thing you would usually get from net/http. Had the request failed one or more times, the above call would block and retry with exponential backoff.

Getting a stdlib *http.Client with retries

It's possible to convert a *retryablehttp.Client directly to a *http.Client. This makes use of retryablehttp broadly applicable with minimal effort. Simply configure a *retryablehttp.Client as you wish, and then call StandardClient():

retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10

standardClient := retryClient.StandardClient() // *http.Client

For more usage and examples see the pkg.go.dev.

Extension points exported contracts — how you extend this code

Logger (Interface)
Logger interface allows to use other loggers than standard log.Logger. [1 implementers]
client.go
ReaderFunc (FuncType)
ReaderFunc is the type of function that can be given natively to NewRequest
client.go
ResponseHandlerFunc (FuncType)
ResponseHandlerFunc is a type of function that takes in a Response, and does something with it. The ResponseHandlerFunc
client.go
LenReader (Interface)
LenReader is an interface implemented by many in-memory io.Reader's. Used for automatically sending the right Content-Le
client.go
LeveledLogger (Interface)
LeveledLogger is an interface that can be implemented by any logger or a logger wrapper to provide leveled logging. The
client.go

Core symbols most depended-on inside this repo

NewClient
called by 26
client.go
Error
called by 19
client.go
Get
called by 17
client.go
Do
called by 15
client.go
NewRequest
called by 12
client.go
DefaultRetryPolicy
called by 10
client.go
redactURL
called by 8
client.go
Printf
called by 6
client.go

Shape

Function 57
Method 23
FuncType 8
Struct 6
Interface 3

Languages

Go100%

Modules by API surface

client.go52 symbols
client_test.go35 symbols
roundtripper_test.go5 symbols
roundtripper.go3 symbols
cert_error_go120.go1 symbols
cert_error_go119.go1 symbols

Dependencies from manifests, versioned

github.com/hashicorp/go-cleanhttpv0.5.2 · 1×
github.com/hashicorp/go-hclogv1.6.3 · 1×
github.com/mattn/go-colorablev0.1.13 · 1×
github.com/mattn/go-isattyv0.0.20 · 1×
golang.org/x/sysv0.20.0 · 1×

For agents

$ claude mcp add go-retryablehttp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact