Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildBaseURL ¶
BuildBaseURL normalises a host string into a base URL. If host already starts with http:// or https://, it is returned as-is (with any trailing slash stripped). Otherwise https:// is prepended.
func SemverLessThan ¶
SemverLessThan is the exported form used in tests.
Types ¶
type APIError ¶
APIError wraps an HTTP error response with status code and body.
func NewAPIError ¶
NewAPIError reads the response body and constructs an APIError. It attempts to extract a JSON "error" or "message" field for the message.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a retryable HTTP client that injects version and auth headers on every outgoing request.
func NewClient ¶
func NewClient(opts ClientOptions) *Client
NewClient creates a Client wrapping hashicorp/go-retryablehttp with 3 retries, exponential backoff between 1s and 30s, and suppressed logging.
func (*Client) Do ¶
Do executes a retryablehttp.Request, injecting version and auth headers before the first attempt and checking the version compatibility header after each successful response.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method, url string, body interface{}) (*retryablehttp.Request, error)
NewRequest is a convenience wrapper around retryablehttp.NewRequest.
func (*Client) StandardClient ¶
StandardClient returns the underlying *http.Client for compatibility with libraries that require a standard net/http client.
type ClientOptions ¶
type ClientOptions struct {
// Host is the base URL for this client (used for display / logging only).
Host string
// Token is the Bearer token sent in the Authorization header.
// If empty, no Authorization header is added.
Token string
// Headers are additional per-host headers injected on every request
// (e.g. Cloudflare Access headers loaded from hosts.yml).
Headers map[string]string
// IOStreams provides the ErrOut writer for version warnings.
IOStreams *iostreams.IOStreams
// AppVersion is the CLI version string sent in the KH-CLI-Version header.
AppVersion string
}
ClientOptions configures a new Client.