httpclient

package
v0.5.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDecodeError added in v0.2.0

func IsDecodeError(err error) bool

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.

func Validate

func Validate(s interface{}) error

Validate validates a struct using the shared validator.

func Validator

func Validator() *validator.Validate

Validator returns the shared validator instance.

Types

type APIError

type APIError struct {
	Method     string
	URL        string
	StatusCode int
	Body       string
	Err        error
}

APIError represents an error response from an API.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

Unwrap returns the underlying error.

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.

func New

func New(cfg Config) *Client

New creates a new HTTP client with the given configuration.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the base URL of the client.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, result interface{}) error

Get performs a GET request and unmarshals the response into result.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}, result interface{}) error

Post performs a POST request with the given body and unmarshals the response into result.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body interface{}, result interface{}) error

Put performs a PUT request with the given body and unmarshals the response into result.

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

func DefaultConfig(baseURL, apiKey string, authType AuthType) Config

DefaultConfig returns a Config with sensible defaults.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL