Documentation ¶
Overview ¶
Package httpclient provides a tiny http client with retry capability.
Index ¶
- func AddAuthorizationBearerHeaderToRequest(req *http.Request, token string)
- func NewJsonRequest(ctx context.Context, method, url string, data any) (*http.Request, error)
- func NewJsonRequestWithHeaders(ctx context.Context, method, url string, data any, headers map[string]string) (*http.Request, error)
- func NewRequest(ctx context.Context, method, url string) (*http.Request, error)
- func NewRequestWithHeaders(ctx context.Context, method, url string, headers map[string]string) (*http.Request, error)
- type Client
- type HttpError
- type Option
- func WithCheckRetryPolicy(checkRetryPolicy retryablehttp.CheckRetry) Option
- func WithHttpClient(httpClient *http.Client) Option
- func WithMaxConnsPerHost(n int) Option
- func WithMaxIdleConns(n int) Option
- func WithMaxIdleConnsPerHost(n int) Option
- func WithMaxRetries(n int) Option
- func WithRequestDumpLogger(requestDumpLogger func(dump []byte), dumpRequestBody bool) Option
- func WithResponseDumpLogger(responseDumpLogger func(dump []byte), dumpResponseBody bool) Option
- func WithRetryWaitMax(n time.Duration) Option
- func WithRetryWaitMin(n time.Duration) Option
- func WithTimeout(t time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAuthorizationBearerHeaderToRequest ¶
AddAuthorizationBearerHeaderToRequest adds bearer authorization header to request.
func NewJsonRequest ¶
NewJsonRequest returns an *http.Request with a json encoded body.
func NewJsonRequestWithHeaders ¶
func NewJsonRequestWithHeaders(ctx context.Context, method, url string, data any, headers map[string]string) (*http.Request, error)
NewJsonRequestWithHeaders returns an *http.Request with a json encoded body and specified headers.
func NewRequest ¶
NewRequest returns an *http.Request.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an http client.
func (*Client) SendRequest ¶
SendRequest sends an HTTP request and returns an HTTP response.
type HttpError ¶
HttpError is an error that wraps an HTTP response and/or an error.
type Option ¶
type Option func(*Client)
Option represents a Client option.
func WithCheckRetryPolicy ¶
func WithCheckRetryPolicy(checkRetryPolicy retryablehttp.CheckRetry) Option
WithCheckRetryPolicy specifies the policy for handling retries, and is called after each request.
func WithHttpClient ¶
WithHttpClient adds a specified httpClient to be used.
func WithMaxConnsPerHost ¶
WithMaxConnsPerHost limits the total number of connections per host.
func WithMaxIdleConns ¶
WithMaxIdleConns defines the maximum number of idle (keep-alive) connections across all hosts.
func WithMaxIdleConnsPerHost ¶
WithMaxIdleConnsPerHost defines the maximum idle (keep-alive) connections to keep per-host.
func WithMaxRetries ¶
WithMaxRetries limits the maximum number of retries.
func WithRequestDumpLogger ¶
WithRequestDumpLogger specifies a function that receives the request dump along its body (optionally) for logging purposes.
func WithResponseDumpLogger ¶ added in v1.0.2
WithResponseDumpLogger specifies a function that receives the response dump along its body (optionally) for logging purposes.
func WithRetryWaitMax ¶
WithRetryWaitMax specifies maximum time to wait before retrying.
func WithRetryWaitMin ¶
WithRetryWaitMin specifies minimum time to wait before retrying.
func WithTimeout ¶
WithTimeout adds a timeout to the client.