Documentation
¶
Index ¶
- Constants
- func Backoff() *backoff.ExponentialBackOff
- func FormData(data interface{}) (io.Reader, error)
- func JSONData(values interface{}) (io.Reader, error)
- func ParseJSON(data io.Reader) (interface{}, error)
- func PrettyPrint(item interface{})
- type BasicAuth
- type Client
- func (c *Client) Delete(request *Request) (*Response, error)
- func (c *Client) Execute(req *Request) (*Response, error)
- func (c *Client) Get(request *Request) (*Response, error)
- func (c *Client) Patch(request *Request) (*Response, error)
- func (c *Client) Post(request *Request) (*Response, error)
- func (c *Client) Put(request *Request) (*Response, error)
- func (c *Client) SetBasicAuth(username string, password string)
- func (c *Client) SetRateLimiterInfo(limitInfo *funnel.RateLimitInfo) error
- type Param
- type Request
- type Response
Constants ¶
const ( DefaultInitialInterval = 100 * time.Millisecond DefaultRandomizationFactor = 0.75 DefaultMultiplier = 2 DefaultMaxInterval = 3 * time.Second DefaultMaxElapsedTime = 5 * time.Second )
GoHTTP Default backoff parameters.
const ( GET = "GET" POST = "POST" PUT = "PUT" PATCH = "PATCH" DELETE = "DELETE" )
HTTP Methods
const ( ContentType = "Content-Type" ContentLength = "Content-Length" Accept = "Accept" Authorization = "Authorization" UserAgent = "User-Agent" )
HTTP Header Constants
Variables ¶
This section is empty.
Functions ¶
func Backoff ¶
func Backoff() *backoff.ExponentialBackOff
Backoff returns a backoff.ExponentialBackOff algorithm with the default GoHTTP backoff policy.
func ParseJSON ¶
ParseJSON parses the JSON data from an `io.Reader` into an `interface{}`. This method utilizes the `UserNumber` feature of the `json.Decoder` which causes the Decoder to unmarshal a number into an interface{} as a Number instead of as a float64.
func PrettyPrint ¶
func PrettyPrint(item interface{})
PrettyPrint prints a JSON representation in a pretty printed manner.
Types ¶
type BasicAuth ¶
type BasicAuth struct { // Username for basic authentication. Username string // Password for basic authentication. Password string }
BasicAuth models a set of basic authentication credentials.
type Client ¶
type Client struct { // BaseURL is base URL used for all requests executed by the client. BaseURL string // Headers model the global headers to be used for all requests issued by the client. Headers http.Header // BasicAuth BasicAuth *BasicAuth // RetryableStatusCodes is an array of codes that are retryable. RetryableStatusCodes []int // Backoff ... Backoff *backoff.ExponentialBackOff // contains filtered or unexported fields }
Client models an HTTP client.
A GoHTTP Client can contain global request parameters, such as a BaseURL, a set of Headers, or Basic Authentication Credentials. All global parameters will be applied to each request executed by the client.
The GoHTTP client also has built in support support for retry (with exponential backoff and rate limiting).
func (*Client) Execute ¶
Execute executes the HTTPc request described with the given `gohttp.Request`.
func (*Client) Patch ¶
Patch performs an HTTP PATCH request with the supplied URL string and parameters.
func (*Client) SetBasicAuth ¶
SetBasicAuth configures basic authentication credentials for the client.
func (*Client) SetRateLimiterInfo ¶
func (c *Client) SetRateLimiterInfo(limitInfo *funnel.RateLimitInfo) error
SetRateLimiterInfo provides..
type Request ¶
type Request struct { // Method is the HTTP method to be used for the request. Method string // Header are the headers for the request. Header http.Header // URL is the route to be used for the request. The URL should be relative to the BaseURL of the client. URL string // Params contains the URL parameters to be used with the request. Params []Param // Body contains the JSON body to be used for the request. Body will be sent as application/json. Body interface{} // Form contains the form to be used for the request. Form will be sent as application/x-www-form-urlencoded. Form interface{} }
Request models an HTTP request.
GoHTTP Request objects are sumbitted to a `gohttp.Client` for execution.
type Response ¶
type Response struct { // Code is the response code for the request. Code int // Data contains the raw response data from an request. Data []byte // Body is the deserialized response body returned from an request. Body interface{} // Error is an error that may have occurred during the request. Error error // Request is the gohttp.Request object used to generate the response. Request *Request }
Response models a response from HTTP request.
The GoHTTP Response object provides a convenient model for handling the result of an HTTP request.
func NewResponse ¶
NewResponse builds a `gohttp.Response` object from an `http.Response` object.