modulepackage
0.0.0-20190401132811-c63e3293a290
Repository: https://github.com/taskcluster/go-got.git
Documentation: pkg.go.dev
# README
Got - HTTP API Calls
Package got is a super simple net/http wrapper that does the right thing for most JSON REST APIs specifically adding:
- Retry logic with exponential back-off,
- Reading of body with a MaxSize to avoid running out of memory,
- Timeout after 30 seconds.
g := got.New()
response, err := g.NewRequest("PUT", url, []byte("...")).Send()
if err == nil {
// handle error
}
// Make a GET request
response, err := g.NewRequest("GET", url, nil).Send()
// or short hand
response, err := g.Get(url).Send()
// Send JSON in a request
request := g.NewRequest("PUT", url, []byte(`{"key": "value"}`))
request.Header.Set("Content-Type": "application/json")
// or short hand
request := g.Put(url, nil)
err := request.JSON(map[string]{"key": "value"})
// Disable retries for a request
request := g.NewRequest("POST", url, []byte(`{"key": "value"}`))
request.Retries = 0 // Defaults to 5
// Disable retries for all requests
g.Retries = 0
For more details see: godoc.org/github.com/taskcluster/go-got
# Functions
DefaultIsTransient determines if an error is transient or persistent.
DefaultMakeRequest creates a http.Request from a got.Request.
New returns a new Got client with sane defaults for most small REST API requests.
# Variables
DefaultBackOff is a simple exponential backoff with delays as follows: 1.
DefaultClient is the default client used by got.New().
ErrResponseTooLarge is used to indicate that the response was larger than the safety limit at MaxSize (defined the request).
# Structs
BackOff configuration for retries.
BadResponseCodeError is used to indicate a non-2xx status code.
Got is a simple HTTP client.
A Request as is ready to be sent.
A Response as received.
# Interfaces
Logger is a simple logging interface.