Documentation
¶
Overview ¶
Package wire holds the JSON conventions of the hub's own APIs, /api/home (internal/admin) and the first-run page's /api/firstrun (internal/firstrun): bodies, times, and MCP Gatekeeper's error form
{"error":"<code>","message":"…"}
so the SPA reads the hub's answers and the gatekeeper's with one client. Some errors add flat keys next to the two: "fields" (a field that failed validation, with a JSON Pointer path), "callId", "jobId".
Index ¶
- Constants
- func Decode(w http.ResponseWriter, r *http.Request, v any) error
- func ErrorBody(e *Error) []byte
- func Headers(w http.ResponseWriter)
- func Marshal(v any) ([]byte, error)
- func OptTime(t time.Time) string
- func Random(n int) string
- func Time(t time.Time) string
- func WriteError(w http.ResponseWriter, err error)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type Error
- type Field
Constants ¶
const MaxBody = 1 << 20
MaxBody caps request bodies.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads a JSON object body into v. An empty body leaves v unchanged. It answers 413 too_large, 415 unsupported_media_type, 400 invalid_json, or 400 invalid_args for a field of the wrong type.
func ErrorBody ¶
ErrorBody is the JSON of e: "error" and "message" first, then "fields", then the extra keys by name.
func Headers ¶
func Headers(w http.ResponseWriter)
Headers sets the headers every API answer carries: no caching and no sniffing.
func Marshal ¶
Marshal is json.Marshal without HTML escaping, so "<" in plugin texts arrives unchanged.
func Time ¶
Time formats t the way the APIs send times: RFC 3339, UTC, milliseconds ("2026-11-15T12:04:05.123Z").
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError writes err in the error form. Anything but an *Error is answered as 500 internal without its text, so the caller logs it first.
Types ¶
type Error ¶
type Error struct {
Status int
Code string
Message string
Fields []Field
Extra map[string]string // flat keys next to "error" and "message", e.g. "callId"
RetryAfter time.Duration // sent as Retry-After (whole seconds, at least 1) when positive
}
Error is an API error with its HTTP status and stable code. Message is English and never holds a secret.