httpx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httpx is the shared HTTP core for provider backends: a client with bounded retries + backoff on transient failures, Retry-After handling, and defensive JSON helpers so an upstream field rename surfaces as SCHEMA_DRIFT, not a panic. Providers classify status codes into domain errors (internal/errs); this layer is transport-only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arr

func Arr(m map[string]any, path string) []any

Arr returns the array at path as []any (nil if absent or not an array).

func AsObj

func AsObj(v any) map[string]any

AsObj coerces an arbitrary element to a JSON object (nil if not).

func Bool

func Bool(m map[string]any, path string) bool

Bool returns the boolean at path.

func Decode

func Decode(b []byte) (map[string]any, error)

func Float

func Float(m map[string]any, path string) float64

Float returns the number at path, coercing numeric strings (e.g. "$12.99" is NOT coerced; pass already-numeric fields). Returns 0 if absent.

func Has

func Has(m map[string]any, path string) bool

Has reports whether path exists (for SCHEMA_DRIFT detection on required containers).

func Int

func Int(m map[string]any, path string) int

Int returns the integer at path.

func Str

func Str(m map[string]any, path string) string

Str returns the string at path (or "" ).

func StrOf

func StrOf(v any, key string) string

StrOf reads a string field from an already-extracted object element.

Types

type Client

type Client struct {
	HTTP       *http.Client
	UserAgent  string
	MaxRetries int           // retries AFTER the first attempt
	BaseDelay  time.Duration // backoff base
}

Client is a thin retrying HTTP client. Zero value is not usable — call New.

func New

func New() *Client

New returns a Client with sane defaults for I/O-bound provider calls.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*Response, error)

Do executes req, retrying on network errors, 429, and 5xx up to MaxRetries with exponential backoff (honoring Retry-After when present). It returns the final Response regardless of status (callers map status → domain errors). A network/exhausted failure returns a non-nil error.

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
}

Response is a fully-read HTTP response.

func (*Response) RetryAfterSeconds

func (r *Response) RetryAfterSeconds() int

RetryAfterSeconds parses the Retry-After header (delta-seconds form), 0 if absent/invalid.

Jump to

Keyboard shortcuts

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