Documentation
¶
Overview ¶
Package respond is what every route shares: reading the request, writing JSON, turning process errors into statuses.
Index ¶
- func Decode(w http.ResponseWriter, r *http.Request, dest any) bool
- func Error(w http.ResponseWriter, r *http.Request, err error)
- func Fail(w http.ResponseWriter, status int, message string)
- func JSON(w http.ResponseWriter, status int, data any)
- func List[T any](w http.ResponseWriter, status int, items []T)
- func Total(w http.ResponseWriter, total int)
- type Failure
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.