Documentation
¶
Overview ¶
Package httputil provides a thin JSON HTTP client shared by promclient, jaegerclient, and dozorclient. Each of those packages previously rolled its own http.Client.Do + json.Decode + status-check + error-wrap; this package consolidates the pattern.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin wrapper around http.Client for JSON GET/POST.
func New ¶
New creates a Client targeting baseURL. Trailing slashes are stripped. Default timeout is 30 s if not overridden via WithTimeout.
func NewWithHTTPClient ¶
NewWithHTTPClient creates a Client that reuses an existing *http.Client. This preserves connection pooling when the caller already manages an http.Client instance (e.g. promclient, jaegerclient, dozorclient).
func (*Client) GetJSON ¶
GetJSON issues GET <base><path> and decodes a successful JSON response into dst (may be nil to discard body). Non-2xx status returns a wrapped error including the status code and up to 256 bytes of body for diagnostics.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHeader ¶
WithHeader returns an Option that adds a fixed header to every request.
func WithTimeout ¶
WithTimeout returns an Option that sets the HTTP client timeout.