Documentation
¶
Overview ¶
Package httpclient provides a shared HTTP client with retry logic and metrics instrumentation.
Package httpclient provides a shared HTTP client with retry logic and metrics instrumentation.
Index ¶
- func IsDecodeError(err error) bool
- func Validate(s interface{}) error
- func Validator() *validator.Validate
- type APIError
- type AuthType
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Get(ctx context.Context, path string, result interface{}) error
- func (c *Client) Post(ctx context.Context, path string, body interface{}, result interface{}) error
- func (c *Client) Put(ctx context.Context, path string, body interface{}, result interface{}) error
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDecodeError ¶ added in v0.2.0
IsDecodeError reports whether err represents a response body that reached us and failed to decode into the expected shape (malformed JSON, or a field whose type didn't match what the target struct expects) -- as opposed to a connectivity failure (couldn't reach the server at all: DNS, dial, timeout) or a non-2xx HTTP status (server reached, but it reported its own error). Verified this session against this client's actual resty-backed behavior for all three cases: a decode failure surfaces as *APIError{StatusCode: 0, Err: *json.UnmarshalTypeError or *json.SyntaxError}; a connectivity failure surfaces as *APIError{StatusCode: 0, Err: *url.Error}; a non-2xx status surfaces as *APIError{StatusCode: <code>, Err: nil}. Distinguishing the first from the other two is what internal/api/media.go's writeMediaAPIError uses to stop saying "tunarr unreachable" for a failure where Tunarr was reached fine and the problem was a response shape schedularr didn't handle.
Types ¶
type AuthType ¶
type AuthType int
AuthType represents the type of authentication to use.
const ( // AuthNone indicates no authentication. AuthNone AuthType = iota // AuthXAPIKey uses X-API-Key header (Tunarr). AuthXAPIKey // AuthXEmbyToken uses X-Emby-Token header (Emby-compatible APIs). AuthXEmbyToken // AuthBearer uses an RFC 6750 "Authorization: Bearer <key>" header // (TheTVDB v4, whose bearer token is minted by a separate login call // rather than configured directly -- see internal/metadata/tvdb). AuthBearer )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps resty.Client with common configuration for API clients.
type Config ¶
type Config struct {
BaseURL string
APIKey string
AuthType AuthType
Timeout time.Duration
MaxRetries int
RetryWaitMin time.Duration
RetryWaitMax time.Duration
}
Config holds the configuration for creating a new HTTP client.
func DefaultConfig ¶
DefaultConfig returns a Config with sensible defaults.