http

package
v0.0.0-...-b787089 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2016 License: MPL-2.0 Imports: 16 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// The maximum number of times to try sending a request before we give up
	// (assuming any unsuccessful attempts can be sensibly tried again).
	MaxSendAttempts = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	http.Client
	// contains filtered or unexported fields
}

func New

func New(credentials *auth.Credentials, apiVersion string, logger *log.Logger) *Client

New returns a new http *Client using the default net/http client.

func (*Client) BinaryRequest

func (c *Client) BinaryRequest(method, url, rfc1123Date string, request *RequestData, response *ResponseData) (err error)

Sends the byte array in reqData.ReqValue (if any) to the specified URL. Optional method arguments are passed using the RequestData object. Relevant RequestData fields: ReqHeaders: additional HTTP header values to add to the request. ExpectedStatus: the allowed HTTP response status values, else an error is returned. ReqReader: an io.Reader providing the bytes to send. RespReader: assigned an io.ReadCloser instance used to read the returned data..

func (*Client) JsonRequest

func (c *Client) JsonRequest(method, url, rfc1123Date string, request *RequestData, response *ResponseData) (err error)

JsonRequest JSON encodes and sends the object in reqData.ReqValue (if any) to the specified URL. Optional method arguments are passed using the RequestData object. Relevant RequestData fields: ReqHeaders: additional HTTP header values to add to the request. ExpectedStatus: the allowed HTTP response status values, else an error is returned. ReqValue: the data object to send. RespValue: the data object to decode the result into.

func (*Client) SetTrace

func (client *Client) SetTrace(traceEnabled bool)

SetTrace allows control over whether requests will write their contents to the logger supplied during construction. Note that this is not safe to call from multiple go-routines.

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type ErrorWrapper

type ErrorWrapper struct {
	Error ErrorResponse `json:"error"`
}

type HttpError

type HttpError struct {
	StatusCode      int
	Data            map[string][]string
	Url             string
	ResponseMessage string
}

func (*HttpError) Error

func (e *HttpError) Error() string

type RequestData

type RequestData struct {
	ReqHeaders http.Header
	Params     *url.Values
	ReqValue   interface{}
	ReqReader  io.Reader
	ReqLength  int
}

type ResponseData

type ResponseData struct {
	ExpectedStatus []int
	RespHeaders    *http.Header
	RespValue      interface{}
	RespReader     io.ReadCloser
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL