Documentation ¶
Overview ¶
Package httpclient provides easy way to crate http client with retry and timeout.
Index ¶
- Constants
- type Backoff
- type Client
- func (c *Client) CheckRetry(try int) bool
- func (c *Client) CheckRetryWithBackoff(try int) bool
- func (c *Client) Do(req *fasthttp.Request, resp *fasthttp.Response) error
- func (c *Client) DoContext(ctx context.Context, req *fasthttp.Request, resp *fasthttp.Response) error
- func (c *Client) DoTimeout(req *fasthttp.Request, resp *fasthttp.Response) error
- func (c *Client) SetTimeout(timeout time.Duration)
Constants ¶
const ( // DefaultRetry - количество ретраев под текущую реализацию переключения между основными api и failover. DefaultRetry = 2 // DefaultTimeout - стандартное время ожидания ответа от сервера. DefaultTimeout = 3 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
Backoff - provide essention backoff parameters.
func NewBackoff ¶
NewBackoff - return function for new backoff calculation.
type Client ¶
type Client struct { RetryMax int // Количество попыток запроса. Timeout time.Duration // Таймаут для http запроса. Backoff *Backoff // Рассчёт времени ожидания между попытками запроса. HTTP *fasthttp.Client // HTTP клиент. // contains filtered or unexported fields }
Client is a convenient API to make HTTP calls. Client also handles automatically retrying failed HTTP requests.
func NewDefault ¶
func NewDefault() Client
NewDefault - return new http client with default params & backoff.
func NewWithMetric ¶
func NewWithMetric(domain string, latencyMetric *prometheus.HistogramVec) Client
NewWithMetric - return new http client with default params & backoff.
func NewWithMetricFunc ¶ added in v1.4.0
NewWithMetricFunc - return new http client with default params & backoff.
func (*Client) CheckRetry ¶ added in v1.2.1
CheckRetry will return a boolean value depending on whether the attempts ended or not.
func (*Client) CheckRetryWithBackoff ¶ added in v1.2.1
CheckRetryWithBackoff will return a boolean value depending on whether the attempts ended or not. If the attempts are over - the value will be returned immediately, if not - the value will be returned after the waiting time set via the backoff function.
func (*Client) Do ¶ added in v1.1.3
Do performs the given http request and fills the given http response.
func (*Client) DoContext ¶ added in v1.2.0
func (c *Client) DoContext(ctx context.Context, req *fasthttp.Request, resp *fasthttp.Response) error
DoContext perform the given request with ctx deadline or waits for response during the given timeout duration.
func (*Client) DoTimeout ¶
DoTimeout performs the given request and waits for response during the given timeout duration.