Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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.
}
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.
Click to show internal directories.
Click to hide internal directories.