client

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package client constructs bounded, context-aware native HTTP clients.

Index

Constants

This section is empty.

Variables

View Source
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

func Classify

func Classify(e error) error

Classify converts upstream/network failures into safe application errors without exposing response bodies.

Types

type Client

type Client struct {
	HTTP *http.Client
	// contains filtered or unexported fields
}

Client owns its configured infrastructure client and supports concurrent operations.

func New

func New(c Config) (*Client, error)

New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.

func (*Client) Close

func (c *Client) Close() error

Close releases owned resources. See package documentation for shutdown ordering.

func (*Client) Do

func (c *Client) Do(r *http.Request) (*http.Response, error)

Do returns a streaming response. The caller owns and must close its body.

func (*Client) Download

func (c *Client) Download(ctx context.Context, url string, destination io.Writer) (int64, error)

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

func (c *Client) DownloadFile(ctx context.Context, url, path string) (err error)

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.

func (*Client) JSON

func (c *Client) JSON(ctx context.Context, method, url string, input, output any) error

JSON bounds the response body and closes it. Non-2xx responses return a status error without exposing their body.

func (*Client) Multipart

func (c *Client) Multipart(ctx context.Context, url string, fields map[string]string, files []MultipartFile, output any) error

Multipart streams form fields/files without buffering whole files. Streaming bodies are never automatically retried.

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

type StatusError struct {
	Status     int
	RetryAfter time.Duration
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL