Documentation
¶
Index ¶
- type Client
- func (c *Client) AddRequestInterceptor(interceptor RequestInterceptor)
- func (c *Client) AddResponseInterceptor(interceptor ResponseInterceptor)
- func (c *Client) Close()
- func (c *Client) Delete(ctx context.Context, url string) ([]byte, error)
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetMetrics() Metrics
- func (c *Client) Patch(ctx context.Context, url string, body interface{}) ([]byte, error)
- func (c *Client) Post(ctx context.Context, url string, body interface{}) ([]byte, error)
- func (c *Client) Put(ctx context.Context, url string, body interface{}) ([]byte, error)
- func (c *Client) Request(ctx context.Context, method, url string, body interface{}) ([]byte, error)
- func (c *Client) SetHeader(key, value string)
- type ClientError
- type ClientOption
- func WithCustomTransport(transport *http.Transport) ClientOption
- func WithDisableCompression(disable bool) ClientOption
- func WithDisableKeepAlives(disable bool) ClientOption
- func WithIdleConnTimeout(d time.Duration) ClientOption
- func WithLogInfoEnabled(enabled bool) ClientOption
- func WithLogger(logger Logger) ClientOption
- func WithMaxConnsPerHost(n int) ClientOption
- func WithMaxIdleConns(n int) ClientOption
- func WithProxy(proxyURL *url.URL) ClientOption
- func WithRateLimit(rps float64, burst int) ClientOption
- func WithRetryConstantBackoff(interval time.Duration) ClientOption
- func WithRetryCustomBackoff(backoff retry.Backoff) ClientOption
- func WithRetryExponentialBackoff(initialInterval, maxInterval, maxJitter time.Duration) ClientOption
- func WithRetryLinearBackoff(interval time.Duration) ClientOption
- func WithRetryRandomIntervalBackoff(minInterval, maxInterval time.Duration) ClientOption
- func WithRetryTimes(maxRetries int) ClientOption
- func WithTLSHandshakeTimeout(d time.Duration) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- type Logger
- type Metrics
- type RequestInterceptor
- type ResponseInterceptor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client represents a custom HTTP client with various optimizations
func NewClient ¶
func NewClient(options ...ClientOption) *Client
NewClient creates a new Client with the given options
func (*Client) AddRequestInterceptor ¶
func (c *Client) AddRequestInterceptor(interceptor RequestInterceptor)
AddRequestInterceptor adds a request interceptor
func (*Client) AddResponseInterceptor ¶
func (c *Client) AddResponseInterceptor(interceptor ResponseInterceptor)
AddResponseInterceptor adds a response interceptor
func (*Client) Close ¶
func (c *Client) Close()
Close cancels the base context and closes any idle connections
func (*Client) GetMetrics ¶
GetMetrics returns the current metrics
type ClientError ¶
type ClientError struct { Op string // operation that failed Err error // underlying error Code int // HTTP status code, if applicable }
ClientError represents all possible errors returned by the client
func (*ClientError) Error ¶
func (e *ClientError) Error() string
type ClientOption ¶
type ClientOption func(client *Client)
ClientOption is a function type for client configuration
func WithCustomTransport ¶
func WithCustomTransport(transport *http.Transport) ClientOption
WithCustomTransport sets custom transport for the client
func WithDisableCompression ¶
func WithDisableCompression(disable bool) ClientOption
WithDisableCompression disables automatic decompression of the response body This can be useful if you want to handle decompression yourself
func WithDisableKeepAlives ¶
func WithDisableKeepAlives(disable bool) ClientOption
WithDisableKeepAlives disables HTTP keep-alives This can be useful if you're dealing with servers that don't support keep-alives well
func WithIdleConnTimeout ¶
func WithIdleConnTimeout(d time.Duration) ClientOption
WithIdleConnTimeout sets the maximum amount of time an idle connection will remain idle before closing itself Lower values can help manage resource usage, but may increase latency for new requests
func WithLogInfoEnabled ¶
func WithLogInfoEnabled(enabled bool) ClientOption
WithLogInfoEnabled sets whether Info logging is enabled for the client
func WithMaxConnsPerHost ¶
func WithMaxConnsPerHost(n int) ClientOption
WithMaxConnsPerHost sets the maximum number of connections per host This can prevent a single host from using too many resources
func WithMaxIdleConns ¶
func WithMaxIdleConns(n int) ClientOption
WithMaxIdleConns sets the maximum number of idle connections Increasing this can improve performance for concurrent requests to many hosts
func WithProxy ¶
func WithProxy(proxyURL *url.URL) ClientOption
WithProxy sets a proxy for the client If proxyURL set nil, no proxy will be used, even if the environment variables are set
func WithRateLimit ¶
func WithRateLimit(rps float64, burst int) ClientOption
WithRateLimit sets rate limiting for requests rps is the maximum number of requests per second burst is the maximum number of requests that can be sent at once
func WithRetryConstantBackoff ¶
func WithRetryConstantBackoff(interval time.Duration) ClientOption
WithRetryConstantBackoff sets a constant backoff strategy for retries
func WithRetryCustomBackoff ¶
func WithRetryCustomBackoff(backoff retry.Backoff) ClientOption
WithRetryCustomBackoff sets a custom backoff strategy for retries
func WithRetryExponentialBackoff ¶
func WithRetryExponentialBackoff(initialInterval, maxInterval, maxJitter time.Duration) ClientOption
WithRetryExponentialBackoff sets an exponential backoff strategy with jitter for retries
func WithRetryLinearBackoff ¶
func WithRetryLinearBackoff(interval time.Duration) ClientOption
WithRetryLinearBackoff sets a linear backoff strategy for retries
func WithRetryRandomIntervalBackoff ¶
func WithRetryRandomIntervalBackoff(minInterval, maxInterval time.Duration) ClientOption
WithRetryRandomIntervalBackoff sets a random interval backoff strategy for retries
func WithRetryTimes ¶
func WithRetryTimes(maxRetries int) ClientOption
WithRetryTimes sets the number of retries for failed requests.
func WithTLSHandshakeTimeout ¶
func WithTLSHandshakeTimeout(d time.Duration) ClientOption
WithTLSHandshakeTimeout sets the maximum amount of time waiting for a TLS handshake Increase this if you're dealing with slow or unreliable networks
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the overall timeout for requests This includes connection time, any redirects, and reading the response body
type Logger ¶
type Logger interface { Info(msg string, keyVals ...interface{}) Error(msg string, keyVals ...interface{}) Warn(msg string, keyVals ...interface{}) }
Logger is a simple interface for logging messages
type RequestInterceptor ¶
RequestInterceptor is a function that can modify requests before they are sent
type ResponseInterceptor ¶
ResponseInterceptor is a function that can modify responses after they are received