Documentation
¶
Overview ¶
Package response constructs typed Huma outputs and safe HTTP problem details. Huma owns serialization, headers and OpenAPI; files and streams use native outputs.
Index ¶
- func Error(ctx context.Context, err error) error
- func LogError(ctx context.Context, err error)
- func RequestID(ctx context.Context) string
- func Transform(_ huma.Context, _ string, value any) (any, error)
- func WithRequestID(ctx context.Context, id string) context.Context
- func WriteError(ctx huma.Context, err error)
- func WriteHTTPError(ctx context.Context, w http.ResponseWriter, err error)
- type Empty
- type Envelope
- type JSON
- type Problem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
Error translates a service failure into safe Huma problem details. Call it when returning a service error from an HTTP handler. Nil stays nil; native Huma status errors and headers are preserved. No global Huma hooks are changed.
func LogError ¶
LogError records a safe operational failure, including errors after a stream starts. It never writes a response; a broken stream must abort its transport.
func RequestID ¶
RequestID returns the server-generated correlation ID for this request. It returns an empty string when no ID has been attached to the context.
func Transform ¶
Transform integrates safe problem details with Huma without changing its global hooks. Huma owns validation; only redact transport diagnostics here: no submitted values or parser internals leave the HTTP boundary, including missing fields.
func WithRequestID ¶
WithRequestID attaches the server-generated correlation ID to a request context. The API server calls this once before middleware and handlers run.
func WriteError ¶
WriteError rejects a request from Huma middleware. Return without invoking next.
func WriteHTTPError ¶
func WriteHTTPError(ctx context.Context, w http.ResponseWriter, err error)
WriteHTTPError writes a service failure from a standard net/http handler. Call before committing headers or body bytes, then return from the handler.
Types ¶
type Empty ¶
type Empty struct{}
Empty declares no response body. Huma defaults bodyless outputs to status 204.
type Envelope ¶
type Envelope[T any] struct { Data T `json:"data"` Meta map[string]any `json:"meta,omitempty" doc:"Optional operation-specific metadata"` }
Envelope keeps the result's concrete type available to Huma's schema generator. Data is always present, including null for a nil result.
type JSON ¶
JSON is a native Huma output. Construct it with NewJSON or a status shortcut; Huma uses Status directly, so a literal with an unset Status is invalid.