Documentation
¶
Index ¶
Constants ¶
const DefaultTimeout = 10 * time.Second
DefaultTimeout is the default per-request timeout.
const MaxResponseBody = 64 * 1024
MaxResponseBody limits how much of a response body is read for errors/decoding.
Variables ¶
This section is empty.
Functions ¶
func IsTransient ¶ added in v0.21.0
IsTransient returns true if err is a transient error.
func ReadBodyLimited ¶ added in v0.21.0
ReadBodyLimited reads at most MaxResponseBody bytes from r.
func RedactSecrets ¶ added in v0.21.0
RedactSecrets removes obvious secrets (tokens, query params) from a string.
Types ¶
type ErrorKind ¶ added in v0.21.0
type ErrorKind string
ErrorKind identifies whether an error is transient or permanent.
func KindFromStatus ¶ added in v0.21.0
KindFromStatus maps HTTP status to error kind.
type HTTPDoer ¶
type HTTPDoer interface {
// DoRequest sends an HTTP request using the given parameters.
//
// Parameters:
// - ctx: A context controlling request timeout and cancellation.
// - method: The HTTP method to use (e.g. "GET", "POST").
// - url: The target URL of the HTTP request.
// - body: The request payload, typically JSON-encoded.
//
// Returns:
// - *http.Response: The raw HTTP response object.
// - error: Any error encountered during request creation or execution.
DoRequest(ctx context.Context, method, url string, body []byte) (*http.Response, error)
}
HTTPDoer defines the interface required to perform an HTTP request.
It allows consumers to inject custom HTTP clients for testability and flexibility.
type HttpClient ¶
type HttpClient struct {
Headers map[string]string // Headers are added to each outbound HTTP request.
SkipInsecure bool // SkipInsecure disables TLS certificate validation when true.
Timeout time.Duration // Timeout is the per-request timeout.
}
HttpClient implements the Doer interface with support for custom headers and TLS options.
func NewHttpClient ¶
func NewHttpClient(headers map[string]string, skipInsecure bool) *HttpClient
NewHttpClient creates a configured HTTP client for issuing requests.
Parameters:
- headers: A map of key-value headers to attach to each request.
- skipInsecure: If true, TLS verification is disabled.
Returns:
- *HttpClient: A client ready to send requests via DoRequest.
func (*HttpClient) DoRequest ¶
func (hc *HttpClient) DoRequest(ctx context.Context, method, url string, body []byte) (*http.Response, error)
DoRequest builds and sends an HTTP request with the given payload and configuration.
Parameters:
- ctx: The request-scoped context for cancellation and timeout.
- method: The HTTP method to use (e.g. "POST").
- url: The request destination.
- body: The payload to include in the request body.
Returns:
- *http.Response: The HTTP response from the remote server.
- error: An error if the request fails to be built or sent.