Documentation
¶
Index ¶
- func DelayWithJitter(baseDelay, jitter time.Duration) time.Duration
- func Sleep(baseDelay, jitter time.Duration)
- type Client
- func (c *Client) Do(req *http.Request) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string) (*Response, error)
- func (c *Client) GetJSON(ctx context.Context, url string, dest any) (*Response, error)
- func (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
- func (c *Client) Head(ctx context.Context, url string) (*Response, error)
- func (c *Client) HeadWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
- func (c *Client) IsAlive(ctx context.Context, url string) bool
- func (c *Client) Post(ctx context.Context, url string, body any) (*Response, error)
- func (c *Client) PostForm(ctx context.Context, requestURL string, values url.Values) (*Response, error)
- func (c *Client) PostFormWithHeaders(ctx context.Context, requestURL string, values url.Values, ...) (*Response, error)
- func (c *Client) PostJSON(ctx context.Context, url string, body any, dest any) (*Response, error)
- func (c *Client) PostWithHeaders(ctx context.Context, url string, body any, headers map[string]string) (*Response, error)
- func (c *Client) Request(ctx context.Context, method, requestURL string, body io.Reader, ...) (*Response, error)
- type Option
- type Options
- type RedirectHop
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DelayWithJitter ¶
DelayWithJitter returns a duration with random jitter applied. The result is between baseDelay and baseDelay + jitter.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps http.Client with Method-specific defaults and helpers.
func (*Client) GetWithHeaders ¶
func (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
GetWithHeaders performs an HTTP GET request with custom headers.
func (*Client) HeadWithHeaders ¶
func (c *Client) HeadWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
HeadWithHeaders performs an HTTP HEAD request with custom headers.
func (*Client) PostForm ¶
func (c *Client) PostForm(ctx context.Context, requestURL string, values url.Values) (*Response, error)
PostForm performs an HTTP POST request with form-encoded body.
func (*Client) PostFormWithHeaders ¶
func (c *Client) PostFormWithHeaders(ctx context.Context, requestURL string, values url.Values, headers map[string]string) (*Response, error)
PostFormWithHeaders performs an HTTP POST request with form-encoded body and custom headers.
func (*Client) PostJSON ¶
PostJSON performs a POST request with a JSON body and unmarshals the response into dest.
type Option ¶
type Option func(*Options)
Option is a functional option for configuring the HTTP client.
func WithBlockCrossDomainRedirects ¶
func WithBlockCrossDomainRedirects() Option
WithBlockCrossDomainRedirects blocks redirects that change the host.
func WithDefaultHeaders ¶
WithDefaultHeaders sets headers that are applied to every request.
func WithMaxRedirects ¶
WithMaxRedirects sets the maximum number of redirects to follow. Set to 0 to disable redirects. Default is 10.
func WithRedirectTracking ¶
func WithRedirectTracking() Option
WithRedirectTracking enables tracking of the full redirect chain in responses.
func WithTLSVerify ¶
WithTLSVerify controls whether TLS certificate verification is enabled.
func WithTimeout ¶
WithTimeout sets the HTTP request timeout.
type Options ¶
type Options struct {
Timeout time.Duration
VerifyTLS bool
MaxRedirects int
TrackRedirects bool
BlockCrossDomainRedirects bool
DefaultHeaders map[string]string
}
Options configures the HTTP client behavior.
type RedirectHop ¶
RedirectHop records a single redirect in the chain.