Documentation
¶
Index ¶
- func DecodeJSON[T any](r *http.Request) (T, error)
- func PathParam(r *http.Request, key string) string
- func QueryParam(r *http.Request, key string) string
- func WriteError(w http.ResponseWriter, status int, code, message string)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- func WriteNoContent(w http.ResponseWriter)
- type ErrorBody
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes the JSON request body into T. Returns a descriptive error for EOF, syntax errors, and type mismatches that callers can map to a 400 response.
func PathParam ¶
PathParam returns the named path parameter from the Go 1.22 ServeMux. Equivalent to r.PathValue(key).
func QueryParam ¶
QueryParam returns a single query string value.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, message string)
WriteError writes a JSON error body { "code": ..., "message": ... }.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, v any)
WriteJSON encodes v as JSON and writes it with the given status code. It encodes into a buffer first so that a marshal error does not leave a partial response body behind.
func WriteNoContent ¶
func WriteNoContent(w http.ResponseWriter)
WriteNoContent writes a 204 No Content response with no body.
Types ¶
Click to show internal directories.
Click to hide internal directories.