Documentation ¶
Index ¶
- Variables
- type AuthFn
- type Client
- func (c *Client) DELETE(addr string) *Request
- func (c *Client) GET(addr string) *Request
- func (c *Client) HEAD(addr string) *Request
- func (c *Client) PATCH(addr string) *Request
- func (c *Client) POST(addr string) *Request
- func (c *Client) PUT(addr string) *Request
- func (c *Client) Req(method, addr string) *Request
- type ClientOptFn
- func WithAuth(authFn AuthFn) ClientOptFn
- func WithBackoff(b backoff.Backoffer) ClientOptFn
- func WithBaseURL(baseURL string) ClientOptFn
- func WithEncode(fn EncodeFn) ClientOptFn
- func WithResetSeekerToZero() ClientOptFn
- func WithRetryClientTimeouts() ClientOptFn
- func WithRetryResponseErrors() ClientOptFn
- type DecodeFn
- type Doer
- type EncodeFn
- type Request
- func (r *Request) Auth(authFn AuthFn) *Request
- func (r *Request) Backoff(b backoff.Backoffer) *Request
- func (r *Request) Body(v interface{}) *Request
- func (r *Request) ContentLength(t int) *Request
- func (r *Request) ContentType(t string) *Request
- func (r *Request) Decode(fn DecodeFn) *Request
- func (r *Request) DecodeJSON(v interface{}) *Request
- func (r *Request) Do(ctx context.Context) error
- func (r *Request) DoAndGetReader(ctx context.Context) (*http.Response, error)
- func (r *Request) Encode(fn EncodeFn) *Request
- func (r *Request) Exists(fn StatusFn) *Request
- func (r *Request) Header(key, value string) *Request
- func (r *Request) Meta(key, value string, pairs ...string) *Request
- func (r *Request) NotFound(fn StatusFn) *Request
- func (r *Request) OnError(fn DecodeFn) *Request
- func (r *Request) QueryParam(key, value string) *Request
- func (r *Request) QueryParams(key, value string, pairs ...string) *Request
- func (r *Request) ResponseHeaders(fn ResponseHeadersFn) *Request
- func (r *Request) Retry(fn RetryFn) *Request
- func (r *Request) RetryResponseErrors() *Request
- func (r *Request) RetryStatus(fn StatusFn) *Request
- func (r *Request) RetryStatusNotIn(status int, rest ...int) *Request
- func (r *Request) SeekParams(offset int64, whence int) *Request
- func (r *Request) Success(fn StatusFn) *Request
- type ResponseErrorFn
- type ResponseHeadersFn
- type RetryFn
- type StatusFn
- func StatusAccepted() StatusFn
- func StatusCreated() StatusFn
- func StatusForbidden() StatusFn
- func StatusIn(status int, others ...int) StatusFn
- func StatusInRange(low, high int) StatusFn
- func StatusInternalServerError() StatusFn
- func StatusNoContent() StatusFn
- func StatusNotFound() StatusFn
- func StatusNotIn(status int, others ...int) StatusFn
- func StatusOK() StatusFn
- func StatusPartialContent() StatusFn
- func StatusSuccessfulRange() StatusFn
- func StatusUnprocessableEntity() StatusFn
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidEncodeFn = errors.New("no encode fn provided for body")
ErrInvalidEncodeFn is an error that is returned when calling the Request Do and the encode function is not set.
Functions ¶
This section is empty.
Types ¶
type AuthFn ¶
AuthFn adds authorization to an http request.
func BearerTokenAuth ¶
BearerTokenAuth sets the token authentication on the request.
func HeaderAuth ¶
HeaderAuth sets the header credential on each request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the httpc client. The client sets the default backoff and encode func on the request that are created when making an http call. Those defaults can be overridden in the request builder.
type ClientOptFn ¶
ClientOptFn sets keys on a client type.
func WithAuth ¶
func WithAuth(authFn AuthFn) ClientOptFn
WithAuth sets the authorization func on the client type, and will be used as the default authFn for all requests from this client unless overwritten atn the request lvl.
func WithBackoff ¶
func WithBackoff(b backoff.Backoffer) ClientOptFn
WithBackoff sets the backoff on the client.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOptFn
WithBaseURL sets the base url for all requests. Any path provided will be appended to this WithBaseURL.
func WithEncode ¶
func WithEncode(fn EncodeFn) ClientOptFn
WithEncode sets the encode func for the client.
func WithResetSeekerToZero ¶
func WithResetSeekerToZero() ClientOptFn
WithResetSeekerToZero sets the seek params to zero for all future requests Useful if Body param is a ReadSeeker and should be reset on retry
func WithRetryClientTimeouts ¶
func WithRetryClientTimeouts() ClientOptFn
WithRetryClientTimeouts sets the response retry mechanism. Useful if you want to retry on a client timeout or something of that nature.
func WithRetryResponseErrors ¶
func WithRetryResponseErrors() ClientOptFn
WithRetryResponseErrors sets the response retry mechanism.
type DecodeFn ¶
DecodeFn is a decoder func.
func GobDecode ¶
func GobDecode(v interface{}) DecodeFn
GobDecode sets the client's decodeFn to a gob decoder.
func JSONDecode ¶
func JSONDecode(v interface{}) DecodeFn
JSONDecode sets the client's decodeFn to a json decoder.
type EncodeFn ¶
EncodeFn is an encoder func.
func JSONEncode ¶
func JSONEncode() EncodeFn
JSONEncode sets the client's encodeFn to a json encoder.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is built up to create an http request.
func (*Request) Auth ¶
Auth sets the authorization for hte request, overriding the authFn set by the client.
func (*Request) ContentLength ¶
ContentLength sets the content length on the request.
func (*Request) ContentType ¶
ContentType sets the content type on the request.
func (*Request) DecodeJSON ¶
DecodeJSON is is a short hand for decoding to JSON.
func (*Request) DoAndGetReader ¶ added in v0.0.37
DoAndGetReader makes the http request and does not close the body in the http.Response that is returned
func (*Request) QueryParam ¶
QueryParam allows a user to set query params on their request. This can be called numerous times. Will add keys for each value that is passed in here. In the case of duplicate query param values, the last pair that is entered will be set and the former will not be available.
func (*Request) QueryParams ¶
QueryParams allows a user to set multiple query params at one time. Following the same rules as QueryParam. If a key is provided without a value, it will not be added to the request. If it is desired, pass in "" to add a query param with no string field.
func (*Request) ResponseHeaders ¶
func (r *Request) ResponseHeaders(fn ResponseHeadersFn) *Request
ResponseHeaders provides a hook to get the headers of a response
func (*Request) RetryResponseErrors ¶
RetryResponseErrors tells the request to retry execution errors.
func (*Request) RetryStatus ¶
RetryStatus sets the retry policy(s) on the request.
func (*Request) RetryStatusNotIn ¶
RetryStatusNotIn sets the retry policy(s) to retry if the response status matches that of the given args.
func (*Request) SeekParams ¶
SeekParams sets the seek params. this is useful in cases where the body is a seeker and needs to be reset on retry
type ResponseErrorFn ¶
ResponseErrorFn is a response error function that can be used to provide behavior when a response fails to "Do".
type ResponseHeadersFn ¶
ResponseHeadersFn is a function that can be used to retrieve headers from a response
type RetryFn ¶
RetryFn will apply a retry policy to a request.
func RetryClientTimeout ¶
func RetryClientTimeout() RetryFn
RetryClientTimeout will retry the request if the request had been canceled by the http client.
func RetryResponseError ¶
func RetryResponseError(fn ResponseErrorFn) RetryFn
RetryResponseError sets a function to be called on all response errors.
func RetryStatus ¶
RetryStatus appends a retry func to the Request.
type StatusFn ¶
StatusFn is func for comparing expected status code against an expected status code.
func StatusAccepted ¶
func StatusAccepted() StatusFn
StatusAccepted compares the response's status code to match Status Accepted.
func StatusCreated ¶
func StatusCreated() StatusFn
StatusCreated compares the response's status code to match Status Created.
func StatusForbidden ¶
func StatusForbidden() StatusFn
StatusForbidden compares the response's status code to match Status Forbidden.
func StatusIn ¶
StatusIn checks whether the response's status code matches at least 1 of the input status codes provided.
func StatusInRange ¶
StatusInRange checks the response's status code is in in the range provided. The range is [low, high).
func StatusInternalServerError ¶
func StatusInternalServerError() StatusFn
StatusInternalServerError compares the response's status code to match Status Internal Server Error.
func StatusNoContent ¶
func StatusNoContent() StatusFn
StatusNoContent compares the response's status code to match Status No Content.
func StatusNotFound ¶
func StatusNotFound() StatusFn
StatusNotFound compares the response's status code to match Status Not Found.
func StatusNotIn ¶
StatusNotIn checks whether the response's status code does match any of the input status codes provided.
func StatusOK ¶
func StatusOK() StatusFn
StatusOK compares the response's status code to match Status OK.
func StatusPartialContent ¶ added in v0.0.37
func StatusPartialContent() StatusFn
StatusPartialContent compares the response's status code to match Status Partial Content
func StatusSuccessfulRange ¶ added in v0.0.37
func StatusSuccessfulRange() StatusFn
StatusSuccessfulRange compares the response's status code to match Status SuccessfulRange.
func StatusUnprocessableEntity ¶
func StatusUnprocessableEntity() StatusFn
StatusUnprocessableEntity compares the response's status code to match Status Unprocessable Entity.