Help us shape the future of Go! Take the 2026 Go Developer Survey

envelope

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package envelope provides the standard JSON response wrapper for all --json output.

Index

Constants

View Source
const SchemaVersion = "v1"

SchemaVersion is the public contract version. Consumers decoding this envelope should branch on major-version changes (v1 -> v2) and expect additive changes within a version. Adding a field is backward-compatible (unknown fields are ignored by Go's json decoder). Renaming or removing a field is a breaking change and requires a major-version bump.

Variables

View Source
var ErrAlreadyWritten = errors.New("error already written to output")

ErrAlreadyWritten signals that an error envelope has already been written to output, so the caller must set a non-zero exit status WITHOUT describing the failure a second time.

It lives here rather than beside one of its users because both the command layer and the query layer produce envelopes and cannot import each other. Before this, only the command layer had a sentinel: the query layer encoded an envelope saying status "error" and returned nil, so `vaultmind note get missing-id --json || handle_failure` never fired.

Functions

func WriteError added in v0.4.2

func WriteError(w io.Writer, env *Envelope) error

WriteError encodes env and returns ErrAlreadyWritten, so that "wrote an error envelope" and "reported success" stop being a state a caller can express. An encoding failure is returned as itself — nothing reached the reader, so there is no envelope for an exit code to agree with.

Types

type Envelope

type Envelope struct {
	SchemaVersion string      `json:"schema_version"`
	Command       string      `json:"command"`
	Status        string      `json:"status"`
	Warnings      []Issue     `json:"warnings"`
	Errors        []Issue     `json:"errors"`
	Result        interface{} `json:"result"`
	Meta          Meta        `json:"meta"`
}

Envelope is the standard JSON response wrapper for all --json output.

func Error

func Error(command, code, message, field string) *Envelope

Error creates an error envelope.

func OK

func OK(command string, result interface{}) *Envelope

OK creates a successful envelope.

func (*Envelope) AddWarning

func (e *Envelope) AddWarning(code, message, field string)

AddWarning adds a structured warning and updates status.

type Issue

type Issue struct {
	Code       string   `json:"code"`
	Message    string   `json:"message"`
	Field      string   `json:"field,omitempty"`
	Candidates []string `json:"candidates,omitempty"`
}

Issue represents a structured warning or error.

type Meta

type Meta struct {
	VaultPath  string `json:"vault_path"`
	IndexHash  string `json:"index_hash"`
	Timestamp  string `json:"timestamp"`
	IndexStale bool   `json:"index_stale,omitempty"`
}

Meta contains envelope metadata.

Jump to

Keyboard shortcuts

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