Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an extensible HTTP client with middleware and optional resiliency hooks.
func New ¶
func New(c *http.Client, mw ...Middleware) *Client
New creates a new Client wrapping c (or a default client with 15s timeout if nil). Middleware options (WithRetry, WithBreaker) must be configured before the first call to Do; the transport chain is assembled once on first use and cannot be modified afterward.
func (*Client) Do ¶
Do sends a request applying middleware and optional resiliency behaviors.
When retry options are set, requests with a body must provide req.GetBody so the body can be re-read on each attempt. Requests without a body (e.g. GET) are retried unconditionally.
func (*Client) WithBreaker ¶
func (c *Client) WithBreaker(b *resiliency.CircuitBreaker) *Client
WithBreaker attaches a circuit breaker to the client.
func (*Client) WithRetry ¶
func (c *Client) WithRetry(opts ...func(*resiliency.RetryOptions)) *Client
WithRetry attaches retry options to the client.
type Middleware ¶
type Middleware func(next http.RoundTripper) http.RoundTripper
Middleware wraps an http.RoundTripper.
func Header ¶
func Header(key, value string) Middleware
Header returns a Middleware that sets the specified header on every request.
func Logging ¶
func Logging(logger *slog.Logger) Middleware
Logging returns a Middleware that logs each request and its duration.
func RequestID ¶
func RequestID(header string) Middleware
RequestID returns a Middleware that injects a unique request ID into the given header if absent.