Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) Client() *http.Client
- func (c *Client) Delete(path string) *Request
- func (c *Client) Deletef(format string, a ...interface{}) *Request
- func (c *Client) Get(path string) *Request
- func (c *Client) Getf(format string, a ...interface{}) *Request
- func (c *Client) Head(path string) *Request
- func (c *Client) Headf(format string, a ...interface{}) *Request
- func (c *Client) Patch(path string) *Request
- func (c *Client) Patchf(format string, a ...interface{}) *Request
- func (c *Client) Post(path string) *Request
- func (c *Client) Postf(format string, a ...interface{}) *Request
- func (c *Client) Put(path string) *Request
- func (c *Client) Putf(format string, a ...interface{}) *Request
- func (c *Client) Request(method, path string) *Request
- func (c *Client) WithBaseURL(url string) *Client
- func (c *Client) WithClient(client *http.Client) *Client
- func (c *Client) WithHeader(key, value string) *Client
- func (c *Client) WithProxy(protocol, addr string) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- func (c *Client) WithTransport(transport http.RoundTripper) *Client
- type Request
- func (r *Request) Bytes() ([]byte, error)
- func (r *Request) Do() (*Response, error)
- func (r *Request) Error() error
- func (r *Request) JSON(out interface{}) error
- func (r *Request) JSONWithError(out interface{}, errOut interface{}) (bool, error)
- func (r *Request) String() (string, error)
- func (r *Request) WithBody(body io.ReadWriter) *Request
- func (r *Request) WithBytes(body []byte) *Request
- func (r *Request) WithContentType(typ string) *Request
- func (r *Request) WithContext(ctx context.Context) *Request
- func (r *Request) WithExpectedStatus(expectedStatusCode int) *Request
- func (r *Request) WithForm(data url.Values) *Request
- func (r *Request) WithHeader(key, value string) *Request
- func (r *Request) WithJSON(body interface{}) *Request
- func (r *Request) WithRetry(retryCount int) *Request
- func (r *Request) WithString(body string) *Request
- func (r *Request) WithXML(body interface{}) *Request
- func (r *Request) XML(out interface{}) error
- func (r *Request) XMLWithError(out interface{}, errOut interface{}) (bool, error)
- type Response
- func (r *Response) Body() io.ReadCloser
- func (r *Response) Bytes() ([]byte, error)
- func (r *Response) Close() error
- func (r *Response) ContentType() string
- func (r *Response) Header() http.Header
- func (r *Response) JSON(out interface{}) error
- func (r *Response) Response() *http.Response
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) String() (string, error)
- func (r *Response) XML(out interface{}) error
- type TransportFunc
Constants ¶
This section is empty.
Variables ¶
var Transports = map[string]TransportFunc{ "http": func(addr string) *http.Transport { u, _ := url.Parse("http://" + addr) return &http.Transport{Proxy: http.ProxyURL(u)} }, "https": func(addr string) *http.Transport { u, _ := url.Parse("http://" + addr) return &http.Transport{Proxy: http.ProxyURL(u)} }, "socks4": func(addr string) *http.Transport { return &http.Transport{Dial: socks.Dial("socks4://" + addr)} }, "socks5": func(addr string) *http.Transport { u, _ := url.Parse("socks5://" + addr) return &http.Transport{Proxy: http.ProxyURL(u)} }, }
Transports is a map of proxy TransportFuncs keyed by their protocol
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an http.Client wrapper
func (*Client) Deletef ¶
Deletef takes a format and a variadic of arguments and returns a prepopulated Delete request
func (*Client) Getf ¶
Getf takes a format and a variadic of arguments and returns a prepopulated Get request
func (*Client) Headf ¶
Headf takes a format and a variadic of arguments and returns a prepopulated Head request
func (*Client) Patchf ¶
Patchf takes a format and a variadic of arguments and returns a prepopulated Patch request
func (*Client) Postf ¶
Postf takes a format and a variadic of arguments and returns a prepopulated Post request
func (*Client) Putf ¶
Putf takes a format and a variadic of arguments and returns a prepopulated Put request
func (*Client) WithBaseURL ¶
WithBaseURL sets the baseURL on the Client
func (*Client) WithClient ¶
WithClient sets the http client on the Client
func (*Client) WithHeader ¶
WithHeader sets the headers on the Client
func (*Client) WithTimeout ¶
WithTimeout sets the timeout on the http Client
func (*Client) WithTransport ¶
func (c *Client) WithTransport(transport http.RoundTripper) *Client
WithTransport sets teh transport on the http Client
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is a type used for configuring, performing and decoding HTTP requests
func (*Request) Bytes ¶
Bytes is a convenience method that handles executing, defer closing, and decoding the body into a slice of bytes before returning
func (*Request) Do ¶
Do performs the base request and returns a populated Response NOTE: As with the standard library, when calling Do you must remember to close the response body : res.Body.Close()
func (*Request) JSON ¶
JSON is a convenience method that handles executing, defer closing, and decoding the JSON body into the passed interface before returning
func (*Request) JSONWithError ¶
JSONWithError is identical to the JSON(...) method but also takes an errOut interface for when the status code isn't expected. In this case the response body will be decoded into the errOut interface and the boolean (expected) will return false
func (*Request) String ¶
String is a convenience method that handles executing, defer closing, and decoding the body into a string before returning
func (*Request) WithBody ¶
func (r *Request) WithBody(body io.ReadWriter) *Request
WithBody sets the body on the request with the passed io.ReadWriter
func (*Request) WithContentType ¶
WithContentType sets the content-type that will be set in the headers on the Request
func (*Request) WithContext ¶
WithContext sets the context on the Request
func (*Request) WithExpectedStatus ¶
WithExpectedStatus sets the desired status-code that will be a success. If the expected status code isn't received an error will be returned or the request will be retried if a count has been set with WithRetry(...)
func (*Request) WithForm ¶
WithForm encodes and sets the passed url.Values as the body to be used on the Request
func (*Request) WithHeader ¶
WithHeader sets a header that will be used on the Request
func (*Request) WithJSON ¶
WithJSON sets the JSON encoded passed interface as the body to be used on the Request
func (*Request) WithRetry ¶
WithRetry sets the desired number of retries on the Request Note: In order to trigger retries you must set an expected status code with the WithExpectedStatus(...) method
func (*Request) WithString ¶
WithString sets the passed string as the body to be used on the Request
func (*Request) WithXML ¶
WithXML sets the XML encoded passed interface as the body to be used on the Request
func (*Request) XML ¶
XML is a convenience method that handles executing, defer closing, and decoding the XML body into the passed interface before returning
func (*Request) XMLWithError ¶
XMLWithError is identical to the XML(...) method but also takes an errOut interface for when the status code isn't expected. In this case the response body will be decoded into the errOut interface and the boolean (expected) will return false
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response contains the raw http.Response reference OR any error that took place while performing the request
func (*Response) Body ¶
func (r *Response) Body() io.ReadCloser
Body returns the io Readcloser body on the Responses http Response
func (*Response) ContentType ¶
ContentType returns the content-type header found on the response
func (*Response) StatusCode ¶
StatusCode returns the status code found on the Response
type TransportFunc ¶
TransportFunc takes an address to a proxy server and returns a fully populated http Transport