Documentation
¶
Overview ¶
Package httpclient provides a common HTTP client for API sources.
Index ¶
Constants ¶
const ( // DefaultMaxRetries is the default number of retry attempts for transient failures. DefaultMaxRetries = 3 // DefaultInitialBackoff is the starting backoff duration before the first retry. DefaultInitialBackoff = 1 * time.Second )
const GitHubDefaultURL = "https://api.github.com"
GitHubDefaultURL is the default GitHub API endpoint.
Variables ¶
This section is empty.
Functions ¶
func Get ¶ added in v1.1.3
Get performs a typed HTTP GET request and decodes the JSON response into T.
func GitHubRateLimitHook ¶ added in v1.1.3
GitHubRateLimitHook inspects GitHub API rate-limit response headers and warns to stderr when the remaining request count is low.
func NormalizeBaseURL ¶ added in v1.0.0
NormalizeBaseURL ensures URL has no trailing slash and applies a default if empty. This is used by clients that need consistent URL handling for API endpoints.
Types ¶
type AuthType ¶
type AuthType int
AuthType defines how authentication is performed.
const ( // AuthNone means no authentication header is set. AuthNone AuthType = iota // AuthBearer uses "Authorization: Bearer <token>". AuthBearer // AuthToken uses "Authorization: token <token>" (Snyk style). AuthToken // AuthBasic uses HTTP Basic auth with token as username and empty password. AuthBasic )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a configurable HTTP client for API requests.
func NewWithHTTPClient ¶
NewWithHTTPClient creates a new HTTP client with a custom http.Client. This is primarily intended for testing.
type Config ¶
type Config struct {
BaseURL string
Token string
AuthType AuthType
Accept string
ExtraHeaders map[string]string
Timeout time.Duration
MaxRetries int // Max retry attempts (0 = use default; -1 = disable)
InitialBackoff time.Duration // Starting backoff before first retry (0 = use default)
OnResponse ResponseHook // Optional callback after successful responses
}
Config holds configuration for the HTTP client.
func GitHubConfig ¶ added in v1.0.0
GitHubConfig returns httpclient.Config pre-configured for GitHub API.
type ResponseHook ¶ added in v1.1.3
ResponseHook is called after each successful HTTP response (status 200). It receives the response headers and can inspect rate-limit or other metadata.