wire

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxBody = 1 << 20

MaxBody caps request bodies.

Variables

This section is empty.

Functions

func Decode

func Decode(w http.ResponseWriter, r *http.Request, v any) error

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

func ErrorBody(e *Error) []byte

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

func Marshal(v any) ([]byte, error)

Marshal is json.Marshal without HTML escaping, so "<" in plugin texts arrives unchanged.

func OptTime

func OptTime(t time.Time) string

OptTime is Time for optional times: "" (omitted with omitempty) when t is zero.

func Random

func Random(n int) string

Random returns n random bytes as base64url without padding.

func Time

func Time(t time.Time) string

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.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON writes v with the status, without HTML escaping.

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.

func Errorf

func Errorf(status int, code, message string) *Error

Errorf returns an Error. The message is used as is.

func Invalid

func Invalid(path, code, message string) *Error

Invalid returns a 400 invalid_args error about one field.

func (*Error) Error

func (e *Error) Error() string

type Field

type Field struct {
	Path    string `json:"path"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

Field is one field that failed validation; Path is a JSON Pointer into the request.

Jump to

Keyboard shortcuts

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