Documentation
¶
Overview ¶
Package apicall is the raw request behind `pgedge starfleet api` and `pgedge controlplane api`: one HTTP call to a path under the module's API base, over the module's own authenticated client, with the module's own status-to-exit mapping and the CLI's output formats.
It exists for the endpoint no verb covers yet, and it is an escape hatch rather than a second interface: gh api and az rest are the precedents that keep their CLI's contract on the raw call, and this does the same (#434).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Methods = []string{"GET", "POST", "PUT", "PATCH", "DELETE"}
Methods is the closed vocabulary; anything else is a usage error.
Functions ¶
func Build ¶
Build validates req against d and returns the http.Request, before anything is sent, so every refusal is exit 2 with no round trip.
func Do ¶
Do sends hreq and prints the response through rt. A non-2xx status goes through d.Check, so the exit code is the one the module's own verbs would give. A 2xx with no body prints nothing on stdout and a sentence on stderr. A JSON body is printed in the requested format, indented in text; any other body is written to stdout as it came.
Types ¶
type Deps ¶
type Deps struct {
Client *http.Client
BaseURL string
Edit func(context.Context, *http.Request) error
Check func(status int, body string) error
UsageErr func(msg string) error
// Transport wraps a failure to reach the server the way the
// module's own verbs do (controlplane adds its reachability hint);
// nil keeps the plain error.
Transport func(err error) error
}
Deps is what a module hands over: its client, base URL, request editor (nil for a client whose transport already authenticates), and its status-to-exit mapping.
type Request ¶
type Request struct {
Method string
Path string
Query []string // key=value, repeatable
Headers []string // Name: value, repeatable
Body []byte
// Include prints the status line and response headers on stderr.
Include bool
}
Request is one call. Path is relative to the base URL and must start with "/"; the host always comes from the parsed base, so a path can at most move within the API the credential was issued for.