apicall

package
v0.5.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: PostgreSQL Imports: 13 Imported by: 0

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 is an escape hatch for the endpoint no verb covers yet, and keeps the CLI's contract on the raw call, as gh api and az rest do.

Index

Constants

This section is empty.

Variables

View Source
var Methods = []string{"GET", "POST", "PUT", "PATCH", "DELETE"}

Methods is the closed vocabulary; anything else is a usage error.

Functions

func Build

func Build(ctx context.Context, d Deps, req Request) (*http.Request, error)

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

func Do(rt *module.Runtime, d Deps, hreq *http.Request, include bool) error

Do sends hreq and prints the response through rt. A non-2xx status goes through d.Check, so the exit code matches the module's verbs.

func ReadBody

func ReadBody(spec string, stdin io.Reader) ([]byte, error)

ReadBody resolves the --data spelling: "@file" reads a file, "-" reads stdin, anything else is the literal body.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL