Documentation ¶
Index ¶
- Variables
- func DecodeJSON(resp *http.Response, res interface{}) error
- func DefaultTransport() *http.Transport
- func InsecureTransport() *http.Transport
- func MarshalJSON(data interface{}) io.Reader
- func New(method, uri string, data io.Reader, headers ...map[string]string) (*http.Request, error)
- func NewTripper(log *util.Logger, transport http.RoundTripper) http.RoundTripper
- func ReadBody(resp *http.Response) ([]byte, error)
- type Helper
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ( // URLEncoding specifies application/x-www-form-urlencoded URLEncoding = map[string]string{"Content-Type": "application/x-www-form-urlencoded"} // JSONEncoding specifies application/json JSONEncoding = map[string]string{ "Content-Type": "application/json", "Accept": "application/json", } // AcceptJSON accepting application/json AcceptJSON = map[string]string{ "Accept": "application/json", } )
var Timeout = 10 * time.Second
Timeout is the default request timeout used by the Helper
Functions ¶
func DecodeJSON ¶
DecodeJSON reads HTTP response and decodes JSON body if error is nil
func DefaultTransport ¶
DefaultTransport returns http.DefaultTransport as http.Transport instead of http.RoundTripper
func InsecureTransport ¶
InsecureTransport is an http.Transport with TLSClientConfig.InsecureSkipVerify enabled
func MarshalJSON ¶
MarshalJSON marshals JSON into an io.Reader
func NewTripper ¶
func NewTripper(log *util.Logger, transport http.RoundTripper) http.RoundTripper
NewTripper creates a logging roundtrip handler
Types ¶
type Helper ¶
Helper provides utility primitives
type StatusError ¶
type StatusError struct {
// contains filtered or unexported fields
}
StatusError indicates unsuccessful http response
func NewStatusError ¶
func NewStatusError(resp *http.Response) StatusError
NewStatusError create new StatusError for given response
func (StatusError) Error ¶
func (e StatusError) Error() string
func (StatusError) HasStatus ¶
func (e StatusError) HasStatus(codes ...int) bool
HasStatus returns true if the respose's status code matches any of the given codes
func (StatusError) Response ¶
func (e StatusError) Response() *http.Response
Response returns the respose with the unexpected error
func (StatusError) StatusCode ¶
func (e StatusError) StatusCode() int
StatusCode returns the respose's status code