Documentation
¶
Overview ¶
Package httpjson is the JSON-over-HTTP round trip and retry loop shared by the chat adapters' platform API clients.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientOr ¶
ClientOr returns client, or a client with the adapters' default 30s timeout when it is nil.
func Redact ¶
Redact replaces secret in err's text so a credential embedded in a request URL never reaches logs.
func Retry ¶
func Retry(ctx context.Context, attempts int, sleep func(context.Context, time.Duration) error, try func() error, pause func(err error, attempt int) (time.Duration, bool)) error
Retry calls try up to attempts times. After a failure, pause reports whether to retry and how long to wait first, given the failed attempt's 0-based index; a non-positive wait retries at once.
func RetryAfter ¶
RetryAfter parses a Retry-After header given in seconds, at most an hour; zero when absent, malformed, not positive or not finite.
Types ¶
type Response ¶
Response is a completed exchange with its body read (at most 4 MiB).
func Do ¶
func Do(ctx context.Context, client *http.Client, method, url string, payload, out any, header ...string) (*Response, error)
Do sends payload as a JSON body (no body when nil, a reader as is) with the given header name/value pairs, which override the default Content-Type, and reads the response. On a 2xx status a non-empty body is decoded into out when out is non-nil. Errors name the failing stage; transport errors pass through.
func Get ¶
func Get(ctx context.Context, client *http.Client, url string, header ...string) (ok *http.Response, failed *Response, err error)
Get sends a GET with the given header pairs. A 200 OK returns the open response for the caller to stream and close; any other status is read, closed and returned as failed.