respond

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 6 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, r *http.Request, err error)

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

func Fail

func Fail(w http.ResponseWriter, status int, message string)

Fail writes an error with this status.

func JSON

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

JSON writes data with this status, compact: agents pay for every byte.

func List

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

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

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.

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