Documentation ¶
Index ¶
- func Backoff(operation func() (*Response, error), options ...Option) error
- func IntranetIP() string
- func IsStringEmpty(str string) bool
- func OutboundIP() string
- func PublicIPs() (ips []string)
- type Client
- type OnRetryFunc
- type Option
- type Options
- type Request
- func (r *Request) Execute(method, url string) (resp *Response, err error)
- func (r *Request) ExecuteWithRetries(method, url string, options ...Option) (resp *Response, err error)
- func (r *Request) Get(url string) (*Response, error)
- func (r *Request) GetWithRetries(url string, options ...Option) (*Response, error)
- func (r *Request) Head(url string) (*Response, error)
- func (r *Request) Send() (*Response, error)
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetDoNotParseResponse(parse bool) *Request
- func (r *Request) SetFormData(data map[string]string) *Request
- func (r *Request) SetHeader(header, value string) *Request
- func (r *Request) SetHeaders(headers map[string]string) *Request
- func (r *Request) SetQueryParam(param, value string) *Request
- func (r *Request) SetQueryParams(params map[string]string) *Request
- type RequestMiddleware
- type Response
- type ResponseMiddleware
- type RetryConditionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Backoff ¶
Backoff retries with increasing timeout duration up until X amount of retries (Default is 3 attempts, Override with option Retries(n))
func IntranetIP ¶
func IntranetIP() string
func IsStringEmpty ¶
func OutboundIP ¶
func OutboundIP() string
Types ¶
type Client ¶
func NewWithClient ¶
func NewWithLocalAddr ¶
NewWithLocalAddr method creates a new client with given Local Address to dial from.
type OnRetryFunc ¶
OnRetryFunc is for side-effecting functions triggered on retry
type Option ¶
type Option func(*Options)
Option is to create convenient retry options like wait time, max retries, etc.
func MaxWaitTime ¶
MaxWaitTime sets the max wait time to sleep between requests
func RetryConditions ¶
func RetryConditions(conditions []RetryConditionFunc) Option
RetryConditions sets the conditions that will be checked for retry.
func RetryHooks ¶
func RetryHooks(hooks []OnRetryFunc) Option
RetryHooks sets the hooks that will be executed after each retry
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options struct is used to hold retry settings.
type Request ¶
type Request struct { URL string Method string QueryParam url.Values FormData url.Values Header http.Header Time time.Time Attempt int RawRequest *http.Request // contains filtered or unexported fields }
func (*Request) Execute ¶
Execute method performs the HTTP request with given HTTP method and URL for current `Request`.
func (*Request) ExecuteWithRetries ¶
func (*Request) GetWithRetries ¶
func (*Request) Head ¶
Head method does HEAD HTTP request. It's defined in section 4.3.2 of RFC7231.
func (*Request) SetDoNotParseResponse ¶
SetDoNotParseResponse
Note: Response middlewares are not applicable, if you use this option.
func (*Request) SetQueryParam ¶
SetQueryParam method sets single parameter and its value in the current request. It will be formed as query string for the request.
For Example: `search=kitchen%20papers&size=large` in the URL after `?` mark.
client.R(). SetQueryParam("search", "kitchen papers"). SetQueryParam("size", "large")
Also you can override query params value, which was set at client instance level.
type RequestMiddleware ¶
RequestMiddleware type is for request middleware, called before a request is sent
type Response ¶
type Response struct { Request *Request RawResponse *http.Response // contains filtered or unexported fields }
Response struct holds response values of executed request.
func (*Response) IsError ¶
IsError method returns true if HTTP status `code >= 400` otherwise false.
func (*Response) IsSuccess ¶
IsSuccess method returns true if HTTP status `code >= 200 and <= 299` otherwise false.
func (*Response) RawBody ¶
func (r *Response) RawBody() io.ReadCloser
RawBody method exposes the HTTP raw response body. Use this method in-conjunction with `SetDoNotParseResponse` option otherwise you get an error as `read err: http: read on closed response body`.
Do not forget to close the body, otherwise you might get into connection leaks, no connection reuse.
func (*Response) ReceivedAt ¶
ReceivedAt method returns when response got received from server for the request.
func (*Response) StatusCode ¶
type ResponseMiddleware ¶
ResponseMiddleware type is for response middleware, called after a response has been received
type RetryConditionFunc ¶
RetryConditionFunc type is for retry condition function input: non-nil Response OR request execution error