Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestHTTPClient ¶
func NewTestHTTPClient(fn RoundTripFunc) *http.Client
NewTestHTTPClient returns a new http.Client that uses the given function as its RoundTripper. This allows for easy mocking of an HTTP client for test purposes. Usually, this function is used in conjunction with the WithHTTPClient function to configure a Client with a mock HTTP client.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
var DefaultClient *Client
func NewClient ¶
func NewClient(options ...ClientOption) (*Client, error)
func (*Client) Query ¶
Query executes a GET request against the given url and returns the response and any errors associated with it.
The HTTP Headers defined under the [clientOptions] struct are added to the request. If the User-Agent header is not set, it is set to the value of the UserAgent field in the [clientOptions] struct.
The response body is limited to the value of the ReaderLimit field in the [clientOptions] struct and an error is returned if the limit is exceeded. Additionally, the response body will be read by this function to facilitate logging, yet returned to the caller as a ReadCloser to be handled like any other response body.
type ClientOption ¶
type ClientOption interface {
// contains filtered or unexported methods
}
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) ClientOption
func WithHeaders ¶
func WithHeaders(headers http.Header) ClientOption
func WithLogger ¶
func WithLogger(logger *slog.Logger) ClientOption
func WithReaderLimit ¶
func WithReaderLimit(limit int64) ClientOption
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption