Documentation ¶
Overview ¶
Package comm provides helpers for communicating with HTTP backends.
Index ¶
- type Client
- func (c *Client) JSONCall(ctx context.Context, endpoint string, headers http.Header, qv url.Values, ...) error
- func (c *Client) SOAPCall(ctx context.Context, endpoint, action string, headers http.Header, ...) error
- func (c *Client) URLFormCall(ctx context.Context, endpoint string, qv url.Values, resp interface{}) error
- func (c *Client) XMLCall(ctx context.Context, endpoint string, headers http.Header, qv url.Values, ...) error
- type HTTPClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a wrapper to our *http.Client that handles compression and serialization needs.
func (*Client) JSONCall ¶
func (c *Client) JSONCall(ctx context.Context, endpoint string, headers http.Header, qv url.Values, body, resp interface{}) error
JSONCall connects to the REST endpoint passing the HTTP query values, headers and JSON conversion of body in the HTTP body. It automatically handles compression and decompression with gzip. The response is JSON unmarshalled into resp. resp must be a pointer to a struct. If the body struct contains a field called "AdditionalFields" we use a custom marshal/unmarshal engine.
func (*Client) SOAPCall ¶
func (c *Client) SOAPCall(ctx context.Context, endpoint, action string, headers http.Header, qv url.Values, body string, resp interface{}) error
SOAPCall returns the SOAP message given an endpoint, action, body of the request and the response object to marshal into.
func (*Client) URLFormCall ¶
func (c *Client) URLFormCall(ctx context.Context, endpoint string, qv url.Values, resp interface{}) error
URLFormCall is used to make a call where we need to send application/x-www-form-urlencoded data to the backend and receive JSON back. qv will be encoded into the request body.
func (*Client) XMLCall ¶
func (c *Client) XMLCall(ctx context.Context, endpoint string, headers http.Header, qv url.Values, resp interface{}) error
XMLCall connects to an endpoint and decodes the XML response into resp. This is used when sending application/xml . If sending XML via SOAP, use SOAPCall().
type HTTPClient ¶
type HTTPClient interface { // Do sends an HTTP request and returns an HTTP response. Do(req *http.Request) (*http.Response, error) // CloseIdleConnections closes any idle connections in a "keep-alive" state. CloseIdleConnections() }
HTTPClient represents an HTTP client. It's usually an *http.Client from the standard library.