Documentation
¶
Index ¶
- type Client
- func (c *Client) Delete(url string) (*Response, error)
- func (c *Client) Fake(fake *Fake) *Client
- func (c *Client) Get(url string) (*Response, error)
- func (c *Client) Head(url string) (*Response, error)
- func (c *Client) Options(url string) (*Response, error)
- func (c *Client) Patch(url string, body any) (*Response, error)
- func (c *Client) Post(url string, body any) (*Response, error)
- func (c *Client) Put(url string, body any) (*Response, error)
- func (c *Client) WithBasicAuth(username, password string) *Client
- func (c *Client) WithBearerToken(token string) *Client
- func (c *Client) WithContext(ctx context.Context) *Client
- func (c *Client) WithHeader(key, value string) *Client
- func (c *Client) WithRetry(attempts int, delay time.Duration) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- type Client2
- func (c *Client2) Async(method, url string, body any, result chan<- *Response2, errChan chan<- error, ...)
- func (c *Client2) Delete(url string, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Do(method, url string, body any, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Get(url string, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Head(url string, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Options(url string, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Patch(url string, body any, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Post(url string, body any, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Put(url string, body any, headers ...map[string]string) (*Response2, error)
- func (c *Client2) Retry(method, url string, body any, maxRetries int, delay time.Duration, ...) (*Response2, error)
- func (c *Client2) SetBaseURL(baseURL string) *Client2
- func (c *Client2) SetHeader(key, value string) *Client2
- func (c *Client2) SetHeaders(headers map[string]string) *Client2
- func (c *Client2) WithBearerToken(token string) *Client2
- func (c *Client2) WithTimeout(timeout time.Duration) *Client2
- type Fake
- func (f *Fake) AssertNotSent(method, url string) bool
- func (f *Fake) AssertSent(method, url string) bool
- func (f *Fake) AssertSentCount(count int) bool
- func (f *Fake) AssertSentJson(method, url string, body any) bool
- func (f *Fake) Clear()
- func (f *Fake) Do(method, url string, body io.Reader) (*Response, error)
- func (f *Fake) Flush()
- func (f *Fake) GetLastRequest() *FakeRequest
- func (f *Fake) GetRequestCount() int
- func (f *Fake) GetRequests() []*FakeRequest
- func (f *Fake) Sequence(method, url string, responses ...*FakeResponse) *Fake
- func (f *Fake) When(method, url string, response *FakeResponse) *Fake
- func (f *Fake) WhenDelete(url string, statusCode int) *Fake
- func (f *Fake) WhenGet(url string, statusCode int, body any) *Fake
- func (f *Fake) WhenPost(url string, statusCode int, body any) *Fake
- func (f *Fake) WhenPut(url string, statusCode int, body any) *Fake
- type FakeRequest
- type FakeResponse
- type Pool
- type Request2
- type Response
- type Response2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a fluent wrapper around net/http.
func (*Client) WithBasicAuth ¶
WithBasicAuth sets Basic Auth headers.
func (*Client) WithBearerToken ¶
WithBearerToken sets a Bearer token in the Authorization header.
func (*Client) WithContext ¶
WithContext returns a new Client that uses the given context for requests.
func (*Client) WithHeader ¶
WithHeader adds a header to the request.
type Client2 ¶
type Client2 struct {
// contains filtered or unexported fields
}
Client2 provides HTTP client functionality
func NewWithTimeout ¶
NewWithTimeout creates a new HTTP client with a custom timeout
func (*Client2) Async ¶
func (c *Client2) Async(method, url string, body any, result chan<- *Response2, errChan chan<- error, headers ...map[string]string)
Async sends a request asynchronously
func (*Client2) Do ¶
func (c *Client2) Do(method, url string, body any, headers ...map[string]string) (*Response2, error)
Do sends an HTTP request
func (*Client2) Retry ¶
func (c *Client2) Retry(method, url string, body any, maxRetries int, delay time.Duration, headers ...map[string]string) (*Response2, error)
Retry sends a request with retries
func (*Client2) SetBaseURL ¶
SetBaseURL sets the base URL for all requests
func (*Client2) SetHeaders ¶
SetHeaders sets multiple default headers
func (*Client2) WithBearerToken ¶
WithBearerToken sets bearer token authentication for the request
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is a fake HTTP client for testing.
func (*Fake) AssertNotSent ¶
AssertNotSent checks that no request was made to the given URL.
func (*Fake) AssertSent ¶
AssertSent checks if a request was made to the given URL.
func (*Fake) AssertSentCount ¶
AssertSentCount checks the exact number of requests made.
func (*Fake) AssertSentJson ¶
AssertSentJson checks if a request was made with the given JSON body.
func (*Fake) GetLastRequest ¶
func (f *Fake) GetLastRequest() *FakeRequest
GetLastRequest returns the last captured request, or nil if none.
func (*Fake) GetRequestCount ¶
GetRequestCount returns the number of requests made.
func (*Fake) GetRequests ¶
func (f *Fake) GetRequests() []*FakeRequest
GetRequests returns all captured requests.
func (*Fake) Sequence ¶
func (f *Fake) Sequence(method, url string, responses ...*FakeResponse) *Fake
Sequence returns a different response for each sequential call to the same URL.
func (*Fake) When ¶
func (f *Fake) When(method, url string, response *FakeResponse) *Fake
When sets up a canned response for a URL pattern.
func (*Fake) WhenDelete ¶
WhenDelete is a convenience method for DELETE requests.
type FakeRequest ¶
FakeRequest captures a request made to the fake.
type FakeResponse ¶
FakeResponse represents a canned response.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a pool of HTTP clients
type Request2 ¶
type Request2 struct {
Method string
URL string
Headers map[string]string
Body any
Timeout time.Duration
BasicUser string
BasicPass string
BearerToken string
QueryParams map[string]string
}
Request2 represents an HTTP request
type Response ¶
Response wraps an http.Response for easier consumption.
func (*Response) StatusCode ¶
StatusCode returns the HTTP status code.
type Response2 ¶
Response2 represents an HTTP response
func (*Response2) IsClientError ¶
IsClientError returns true if the status code is 4xx
func (*Response2) IsRedirect ¶
IsRedirect returns true if the status code is 3xx
func (*Response2) IsServerError ¶
IsServerError returns true if the status code is 5xx
func (*Response2) IsSuccessful ¶
IsSuccessful returns true if the status code is 2xx