respond

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 43 Imported by: 1 module, 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 respond is what every route shares: reading the request, writing JSON, turning process errors into statuses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(w http.ResponseWriter, r *http.Request, dest any) bool

Decode reads the JSON body into dest; on false the response is already written.

func Error

func Error(w http.ResponseWriter, err error)

Error writes the status of a process error. An unknown error is a bug or an outage: its detail may expose SQL or connection strings, so it only goes to the logs.

func ID

ID reads {id} from the path. Not a uuid means no such item, and the check keeps Postgres from raising an error that not every process translates. On false the response is already written.

func JSON

func JSON(w http.ResponseWriter, status int, data any)

JSON writes data with this status.

func List

func List[T any](w http.ResponseWriter, status int, items []T)

List writes a list: an empty one is [], not null.

func Paging

func Paging(w http.ResponseWriter, r *http.Request) (limit, offset int, ok bool)

Paging reads ?limit=&offset= for a process that lists by pages, 0 when left out (no limit: all of them). On false the response is already written.

func Total

func Total(w http.ResponseWriter, total int)

Total counts in X-Total-Count the whole list a page comes from. Before the body.

func ValidIDs

func ValidIDs(w http.ResponseWriter, ids ...string) bool

ValidIDs checks the uuids given in a body or a query, where empty means none (the root); on false the response is already written.

Types

type Failure

type Failure struct {
	Error string `json:"error"`
}

Failure is the body of every error.

Jump to

Keyboard shortcuts

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