Documentation
¶
Overview ¶
Package api provides the api client
Index ¶
- Constants
- type Client
- func (c *Client) DeleteJSON(ctx context.Context, endpoint string, out any) error
- func (c *Client) GetJSON(ctx context.Context, endpoint string, query map[string]string, out any) error
- func (c *Client) PatchJSON(ctx context.Context, endpoint string, query map[string]string, in, out any) error
- func (c *Client) PostJSON(ctx context.Context, endpoint string, query map[string]string, in, out any) error
- func (c *Client) PutJSON(ctx context.Context, endpoint string, in any) error
- func (c *Client) Request(ctx context.Context, method, endpoint string, query map[string]string, ...) (*http.Response, error)
- func (c *Client) SetClientInfo(id, uuid, version string)
- func (c *Client) Stats() *models.Stats
- type DoFunc
- type HTTPError
- type Middleware
- type Option
- type Options
- type RetryPolicy
- type Stats
Constants ¶
const (
// APIBasePath is the entry point of the API
APIBasePath = "/api/v0/"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the low-level HTTP API client
func (*Client) DeleteJSON ¶
DeleteJSON makes a DELETE request with JSON handling
func (*Client) GetJSON ¶
func (c *Client) GetJSON(ctx context.Context, endpoint string, query map[string]string, out any) error
GetJSON makes a GET request with JSON handling
func (*Client) PatchJSON ¶
func (c *Client) PatchJSON(ctx context.Context, endpoint string, query map[string]string, in, out any) error
PatchJSON makes a PATCH request with JSON handling
func (*Client) PostJSON ¶
func (c *Client) PostJSON(ctx context.Context, endpoint string, query map[string]string, in, out any) error
PostJSON makes a POST request with JSON handling
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, method, endpoint string, query map[string]string, body any) (*http.Response, error)
Request makes a raw HTTP request to the API
func (*Client) SetClientInfo ¶
SetClientInfo configures client-identification headers.
Empty values mean "do not set" for that header.
type Middleware ¶
Middleware wraps a DoFunc to provide additional functionality
func LogRequestBodyMiddleware ¶
func LogRequestBodyMiddleware(logger *slog.Logger) Middleware
LogRequestBodyMiddleware logs request bodies for debugging
func LoggingMiddleware ¶
func LoggingMiddleware(logger *slog.Logger) Middleware
LoggingMiddleware logs HTTP requests and responses
func RetryMiddleware ¶
func RetryMiddleware(policy RetryPolicy) Middleware
RetryMiddleware implements retry logic with exponential backoff
func StatsMiddleware ¶
func StatsMiddleware(stats *Stats) Middleware
StatsMiddleware collects API call statistics
func UserAgentMiddleware ¶
func UserAgentMiddleware(userAgent string) Middleware
UserAgentMiddleware adds a User-Agent header to requests
type Option ¶
type Option func(*Options)
Option is a functional option for configuring the API client
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client
func WithMiddlewares ¶
func WithMiddlewares(middlewares ...Middleware) Option
WithMiddlewares sets the middleware chain
type Options ¶
type Options struct {
HTTPClient *http.Client
Middlewares []Middleware
EnableStats bool
}
Options configures the API client
type RetryPolicy ¶
type RetryPolicy struct {
MaxRetries int
InitialDelay time.Duration
MaxDelay time.Duration
BackoffFactor float64
}
RetryPolicy defines retry behavior
func DefaultRetryPolicy ¶
func DefaultRetryPolicy() RetryPolicy
DefaultRetryPolicy returns a sensible default retry policy
type Stats ¶
Stats holds basic API call statistics
func (*Stats) GetSnapshot ¶
GetSnapshot returns a thread-safe copy of current stats