api

package
v0.0.0-...-85df02f Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package api holds the JSON, input and RFC 9457 problem-details helpers shared by every HTTP API.

Index

Constants

View Source
const MaxBodyBytes = 1 << 20

MaxBodyBytes bounds every JSON request body.

Variables

This section is empty.

Functions

func DecodeJSON

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

DecodeJSON reads one JSON object into v, rejecting unknown fields, trailing data and bodies larger than MaxBodyBytes. The returned error is safe to show to the client.

func Error

func Error(w http.ResponseWriter, r *http.Request, status int, detail string)

Error writes a problem with only a status and a detail.

func Printable

func Printable(s string) bool

Printable reports whether s is valid UTF-8 without control characters, the rule for free text that reaches storage, logs or emails.

func WriteJSON

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

WriteJSON writes v with the given status.

func WriteProblem

func WriteProblem(w http.ResponseWriter, r *http.Request, status int, detail string, ext map[string]any)

WriteProblem writes an RFC 9457 problem of type about:blank with the status text as title. ext adds members such as a machine-readable code; the request's trace ID is added so a client report leads to the logs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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