Documentation
¶
Overview ¶
Package client constructs bounded, context-aware native HTTP clients.
Index ¶
- Variables
- func Classify(e error) error
- type Client
- func (c *Client) Close() error
- func (c *Client) Do(r *http.Request) (*http.Response, error)
- func (c *Client) Download(ctx context.Context, url string, destination io.Writer) (int64, error)
- func (c *Client) DownloadFile(ctx context.Context, url, path string) (err error)
- func (c *Client) JSON(ctx context.Context, method, url string, input, output any) error
- func (c *Client) Multipart(ctx context.Context, url string, fields map[string]string, ...) error
- type Config
- type MultipartFile
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ErrResponseTooLarge = errors.New("http client: response limit exceeded")
ErrResponseTooLarge indicates a bounded stream exceeded its configured size. The underlying body has been closed.
Functions ¶
Types ¶
type Client ¶
Client owns its configured infrastructure client and supports concurrent operations.
func New ¶
New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.
func (*Client) Close ¶
Close releases owned resources. See package documentation for shutdown ordering.
func (*Client) Download ¶
Download streams a successful response into destination with the configured response size bound. A failed download may have partially written destination; use DownloadFile for atomic replacement.
func (*Client) DownloadFile ¶
DownloadFile writes a sibling temporary file and atomically replaces path only after a complete successful response. Files use mode 0600. Failed/canceled downloads remove the temporary file and preserve the previous destination.
type Config ¶
type Config struct {
HTTPClient *http.Client
ResponseHeaderTimeout time.Duration
Headers http.Header
RequestID func(context.Context) string
Propagate func(context.Context, http.Header)
RetryPolicy *retry.Policy
RetryMethods []string
MaxRetryAfter time.Duration
Clock clock.Clock
Observer instrument.Hook
Breaker *resilience.Breaker
Timeout, DialTimeout, IdleTimeout time.Duration
MaxIdleConns, MaxConnsPerHost int
TLS *tls.Config
Transport http.RoundTripper
MaxResponseBytes int64
}
Config contains explicit constructor settings; see package documentation for defaults.
type MultipartFile ¶
type MultipartFile struct{ Field, Path, Filename, ContentType string }
MultipartFile describes a local regular file. The SDK owns and closes its temporary file handles. Filename defaults to the path's base name; no local directory is sent to the server.
type StatusError ¶
StatusError contains an HTTP failure status without its potentially sensitive response body.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Error returns a diagnostic error description.