Documentation
¶
Overview ¶
Package http provides shared HTTP client helpers (e.g. base-URL transport) for code that calls external HTTP APIs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
NewClient builds an *nethttp.Client with BaseURLTransport configured. Callers are responsible for layering additional transports (e.g. auth) and setting Timeout on the returned client.
func SendRequest ¶
func SendRequest(ctx context.Context, client *nethttp.Client, method, rawURL string, body []byte, setHeaders func(*nethttp.Request)) (statusCode int, respBody []byte, err error)
SendRequest builds a request from method, rawURL, and body, applies setHeaders to it (when non-nil), sends it via client, and returns the response status code and full body. It does not interpret the status code or decode the body — success, retry, and not-found semantics vary by API, so that judgment stays with the caller.
Types ¶
type BaseURLTransport ¶
type BaseURLTransport struct {
// BaseURL is the API base URL (e.g. "https://api.github.com").
BaseURL *url.URL
// Next is the underlying RoundTripper. Defaults to nethttp.DefaultTransport if nil.
Next nethttp.RoundTripper
}
BaseURLTransport is a nethttp.RoundTripper that rewrites every request URL to resolve against a fixed base URL. This allows callers to make requests with relative paths (e.g. "/graphql") and have the transport prepend the configured base URL transparently.
func (*BaseURLTransport) RoundTrip ¶
RoundTrip rewrites req.URL to resolve against BaseURL, then delegates to Next. The base URL path and request path are joined explicitly so that base URLs with a path component (e.g. "https://ghe.example.com/api") are handled correctly regardless of whether the request path starts with "/".