Documentation ¶
Index ¶
- Constants
- Variables
- func NewGetRequest(apiURI, path string, params url.Values) (*http.Request, error)
- func NewPostRequest(apiURI, path string, requestBody interface{}) (*http.Request, error)
- func NewSignedGetRequest(apiURI, path string, signer identity.Signer) (*http.Request, error)
- func NewSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error)
- func NewSignedPutRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error)
- func NewSignedRequest(httpMethod, apiURI, path string, requestBody interface{}, ...) (*http.Request, error)
- func NewTransport(dialFunc DialContext) *http.Transport
- func ParseResponseError(response *http.Response) error
- func ParseResponseJSON(response *http.Response, dto interface{}) error
- type DialContext
- type Dialer
- type DialerSwarm
- type ErrorDial
- type ErrorSwarmDial
- type HTTPClient
- func (c *HTTPClient) Do(req *http.Request) (*http.Response, error)
- func (c *HTTPClient) DoRequest(req *http.Request) error
- func (c *HTTPClient) DoRequestAndParseResponse(req *http.Request, resp interface{}) error
- func (c *HTTPClient) DoRequestViaProxy(req *http.Request, proxyPort int) error
- func (c *HTTPClient) DoRequestViaProxyAndParseResponse(req *http.Request, resp interface{}, proxyPort int) error
- func (c *HTTPClient) DoViaProxy(req *http.Request, proxyPort int) (*http.Response, error)
Constants ¶
const ( // DefaultTimeout is a default HTTP client timeout. DefaultTimeout = 20 * time.Second )
Variables ¶
var ErrAllDialsFailed = errors.New("all dials failed")
ErrAllDialsFailed is returned when connecting to a peer has ultimately failed.
Functions ¶
func NewGetRequest ¶
NewGetRequest generates http Get request
func NewPostRequest ¶
NewPostRequest generates http Post request
func NewSignedGetRequest ¶
NewSignedGetRequest signs empty message and generates http Get request
func NewSignedPostRequest ¶
func NewSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error)
NewSignedPostRequest signs payload and generates http Post request
func NewSignedPutRequest ¶
func NewSignedPutRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error)
NewSignedPutRequest signs payload and generates http Put request
func NewSignedRequest ¶
func NewSignedRequest(httpMethod, apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error)
NewSignedRequest signs payload and generates http request
func NewTransport ¶
func NewTransport(dialFunc DialContext) *http.Transport
NewTransport returns default HTTP transport which should be reused as it caches underlying TCP connections. If connections pooling is not needed consider to set DisableKeepAlives=false and MaxIdleConnsPerHost=-1.
func ParseResponseError ¶
ParseResponseError parses http.Response error.
func ParseResponseJSON ¶
ParseResponseJSON parses http.Response into given struct.
Types ¶
type DialContext ¶
DialContext specifies the dial function for creating unencrypted TCP connections.
type Dialer ¶
type Dialer struct { // ResolveContext specifies the resolve function for doing custom DNS lookup. // If ResolveContext is nil, then the transport dials using package net. ResolveContext resolver.ResolveContext // Dialer specifies the dial function for creating unencrypted TCP connections. Dialer DialContext }
Dialer wraps default go dialer with extra features.
type DialerSwarm ¶
type DialerSwarm struct { // ResolveContext specifies the resolve function for doing custom DNS lookup. // If ResolveContext is nil, then the transport dials using package net. ResolveContext resolver.ResolveContext // Dialer specifies the dial function for creating unencrypted TCP connections. Dialer DialContext // contains filtered or unexported fields }
DialerSwarm is a dials to multiple addresses in parallel and earliest successful connection wins.
func NewDialerSwarm ¶
func NewDialerSwarm(srcIP string, dnsHeadstart time.Duration) *DialerSwarm
NewDialerSwarm creates swarm dialer with default configuration.
func (*DialerSwarm) DialContext ¶
DialContext connects to the address on the named network using the provided context.
type ErrorDial ¶
ErrorDial is the error returned when dialing a specific address.
type ErrorSwarmDial ¶
ErrorSwarmDial is the error type returned when dialing multiple addresses.
func (*ErrorSwarmDial) Error ¶
func (e *ErrorSwarmDial) Error() string
Error returns string equivalent for error.
func (*ErrorSwarmDial) Unwrap ¶
func (e *ErrorSwarmDial) Unwrap() error
Unwrap unwraps the original err for use with errors.Unwrap.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient describes a client for performing HTTP requests.
func NewHTTPClient ¶
func NewHTTPClient(srcIP string, timeout time.Duration) *HTTPClient
NewHTTPClient creates a new HTTP client.
func NewHTTPClientWithTransport ¶
func NewHTTPClientWithTransport(transport *http.Transport, timeout time.Duration) *HTTPClient
NewHTTPClientWithTransport creates a new HTTP client with custom transport.
func (*HTTPClient) DoRequest ¶
func (c *HTTPClient) DoRequest(req *http.Request) error
DoRequest performs HTTP requests and parses error without returning response.
func (*HTTPClient) DoRequestAndParseResponse ¶
func (c *HTTPClient) DoRequestAndParseResponse(req *http.Request, resp interface{}) error
DoRequestAndParseResponse performs HTTP requests and response from JSON.
func (*HTTPClient) DoRequestViaProxy ¶
func (c *HTTPClient) DoRequestViaProxy(req *http.Request, proxyPort int) error
DoRequestViaProxy performs HTTP requests via proxy and parses error without returning response.
func (*HTTPClient) DoRequestViaProxyAndParseResponse ¶
func (c *HTTPClient) DoRequestViaProxyAndParseResponse(req *http.Request, resp interface{}, proxyPort int) error
DoRequestViaProxyAndParseResponse performs HTTP requests and response from JSON.
func (*HTTPClient) DoViaProxy ¶
DoViaProxy send an HTTP request via proxy and returns an HTTP response.