Documentation
¶
Index ¶
- Constants
- func UnmarshalTo[T any](response *Response) (T, error)
- type Client
- func (c *Client) Delete(ctx context.Context, path string, options ...RequestOption) (*Response, error)
- func (c *Client) Get(ctx context.Context, path string, options ...RequestOption) (*Response, error)
- func (c *Client) Patch(ctx context.Context, path string, body interface{}, options ...RequestOption) (*Response, error)
- func (c *Client) Post(ctx context.Context, path string, body interface{}, options ...RequestOption) (*Response, error)
- func (c *Client) Put(ctx context.Context, path string, body interface{}, options ...RequestOption) (*Response, error)
- func (c *Client) Request(ctx context.Context, method, path string, body interface{}, ...) (*Response, error)
- type ClientOption
- func WithBaseURL(url string) ClientOption
- func WithHeader(key, value string) ClientOption
- func WithHeaders(headers map[string]string) ClientOption
- func WithMiddleware(middleware Middleware) ClientOption
- func WithRetry(opts RetryOptions) ClientOption
- func WithRetryMax(max int) ClientOption
- func WithRetryPolicy(policy retryablehttp.CheckRetry) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTracing() ClientOption
- func WithoutRetry() ClientOption
- type Middleware
- type RequestOption
- type Response
- type RetryOptions
Constants ¶
const ( DefaultRetryMax = 3 DefaultRetryWaitMin = 1 * time.Second DefaultRetryWaitMax = 30 * time.Second )
Default retry values
Variables ¶
This section is empty.
Functions ¶
func UnmarshalTo ¶
UnmarshalTo is a generic helper to decode the response into a struct
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper around http.Client with additional functionality
func New ¶
func New(options ...ClientOption) *Client
New creates a new HTTP client with the given options
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, path string, options ...RequestOption) (*Response, error)
Delete sends a DELETE request and returns the response
func (*Client) Patch ¶
func (c *Client) Patch(ctx context.Context, path string, body interface{}, options ...RequestOption) (*Response, error)
Patch sends a PATCH request and returns the response
func (*Client) Post ¶
func (c *Client) Post(ctx context.Context, path string, body interface{}, options ...RequestOption) (*Response, error)
Post sends a POST request and returns the response
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that configures a Client
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL sets the base URL for the client
func WithHeader ¶
func WithHeader(key, value string) ClientOption
WithHeader adds a header to all requests
func WithHeaders ¶
func WithHeaders(headers map[string]string) ClientOption
WithHeaders adds multiple headers to all requests
func WithMiddleware ¶
func WithMiddleware(middleware Middleware) ClientOption
WithMiddleware adds a middleware to the client
func WithRetry ¶
func WithRetry(opts RetryOptions) ClientOption
WithRetry sets the retry options for the client
func WithRetryMax ¶
func WithRetryMax(max int) ClientOption
WithRetryMax sets the maximum number of retries for the client
func WithRetryPolicy ¶
func WithRetryPolicy(policy retryablehttp.CheckRetry) ClientOption
WithRetryPolicy sets a custom retry policy for the client
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the timeout for the client
func WithTracing ¶
func WithTracing() ClientOption
WithTracing enables tracing using a RoundTripper approach
type Middleware ¶
Middleware is a function that wraps an HTTP request
func AuthBearerMiddleware ¶
func AuthBearerMiddleware(token string) Middleware
AuthBearerMiddleware adds a Bearer token to the Authorization header
func BasicAuthMiddleware ¶
func BasicAuthMiddleware(username, password string) Middleware
BasicAuthMiddleware adds basic authentication to the request
type RequestOption ¶
type RequestOption func(*requestOptions)
RequestOption is a function that configures a request
func WithRequestHeader ¶
func WithRequestHeader(key, value string) RequestOption
WithRequestHeader adds a header to a specific request
type Response ¶
Response is a wrapper around http.Response with additional functionality
type RetryOptions ¶
type RetryOptions struct {
// Enabled determines if retries are enabled
Enabled bool
// Max is the maximum number of retries
Max int
// WaitMin is the minimum time to wait between retries
WaitMin time.Duration
// WaitMax is the maximum time to wait between retries
WaitMax time.Duration
// CheckRetry specifies a policy for handling retries
CheckRetry retryablehttp.CheckRetry
}
RetryOptions configures the retry behavior of the client
func DefaultRetryOptions ¶
func DefaultRetryOptions() RetryOptions
DefaultRetryOptions returns the default retry options