Documentation
¶
Overview ¶
Package client contains functions required to make HTTP calls.
Index ¶
- Constants
- Variables
- func B64BasicAuth(u, p string) (string, error)
- func BodyReader(v interface{}) (io.ReadSeeker, error)
- func Configure(c *config.Client)
- func Invoke(context string, req *HTTPRequest, body interface{}, expectedRespCode int) error
- func ParseBody(res *http.Response, v interface{}) error
- type BackOffPolicy
- type Client
- type HTTPRequest
- func CreateHTTPDELETERequest(token, url string) (*HTTPRequest, error)
- func CreateHTTPGETRequest(token, url string) (*HTTPRequest, error)
- func CreateHTTPPOSTRequest(token, url string, body io.ReadSeeker) (*HTTPRequest, error)
- func CreateHTTPPUTRequest(token, url string, body io.ReadSeeker) (*HTTPRequest, error)
- func CreateHTTPRequest(method, url string, body io.ReadSeeker) (*HTTPRequest, error)
- type InvokeError
- type RetryPolicy
Constants ¶
const ( HeaderAuth = "Authorization" HeaderBear = "Bearer " HTTPContentType = "Content-Type" ContentTypeApplicationJSON = "application/json" ContentTypeURLEncoded = "application/x-www-form-urlencoded; param=value" ErrMsgUnableToCreateReq = "unable to create request" ErrMsgUnableToParseReqBody = "unable to parse request body" ErrMsgUnableToParseRespBody = "unable to parse response body, context: %s " ErrMsgUnableInitiateReq = "unable to initiate request: %s" ErrMsgUnsuccessfulAPICall = "unsuccessful API call: %s response Code: %s URL: %s" ErrMsgUnableToCloseBody = "unable to close the body" )
Variables ¶
var ErrInvalidParameters = errors.New("invalid parameters")
Functions ¶
func B64BasicAuth ¶
B64BasicAuth returns a base64 encoded value of "u:p" string and any error encountered.
func BodyReader ¶
func BodyReader(v interface{}) (io.ReadSeeker, error)
BodyReader returns the byte buffer representation of the provided struct and any error encountered.
func Configure ¶
Configure overrides the default client values. This function should be called before calling Invoke method.
func Invoke ¶
func Invoke(context string, req *HTTPRequest, body interface{}, expectedRespCode int) error
Invoke the request and parse the response body to the given struct. context parameter is used to maintain the request context in the log. resCode parameter is used to determine the desired response code. Returns any error encountered.
Types ¶
type BackOffPolicy ¶
BackOffPolicy policy determines the duration between two retires
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represent the state of the HTTP client.
type HTTPRequest ¶
type HTTPRequest struct {
// contains filtered or unexported fields
}
HTTPRequest wraps the http.request and the Body. Body is wrapped with io.ReadSeeker which allows to reset the body buffer reader to initial state in retires.
func CreateHTTPDELETERequest ¶
func CreateHTTPDELETERequest(token, url string) (*HTTPRequest, error)
CreateHTTPDELETERequest returns a DELETE HTTP request with a Bearer token header and any error encountered.
func CreateHTTPGETRequest ¶
func CreateHTTPGETRequest(token, url string) (*HTTPRequest, error)
CreateHTTPGETRequest returns a GET HTTP request with a Bearer token header and any error encountered.
func CreateHTTPPOSTRequest ¶
func CreateHTTPPOSTRequest(token, url string, body io.ReadSeeker) (*HTTPRequest, error)
CreateHTTPPOSTRequest returns a POST HTTP request with a Bearer token header with the content type to application/json and any error encountered.
func CreateHTTPPUTRequest ¶
func CreateHTTPPUTRequest(token, url string, body io.ReadSeeker) (*HTTPRequest, error)
CreateHTTPPUTRequest returns a PUT HTTP request with a Bearer token header with the content type to application/json and any error encountered.
func CreateHTTPRequest ¶
func CreateHTTPRequest(method, url string, body io.ReadSeeker) (*HTTPRequest, error)
CreateHTTPRequest returns client.HTTPRequest struct which wraps the http.request, request Body, and any error encountered.
func (*HTTPRequest) HTTPRequest ¶
func (r *HTTPRequest) HTTPRequest() *http.Request
HTTPRequest returns the HTTP request.
func (*HTTPRequest) SetHeader ¶
func (r *HTTPRequest) SetHeader(k, v string)
SetHeader method set the given header key and value to the HTTP request.
type InvokeError ¶
type InvokeError struct { StatusCode int // contains filtered or unexported fields }
InvokeError wraps more information about the error.
func (*InvokeError) Error ¶
func (e *InvokeError) Error() string
type RetryPolicy ¶
RetryPolicy defines a function which validate the response and apply desired policy to determine whether to retry the particular request or not.