Documentation ¶
Index ¶
- func BodyAsJSON[T any](r *http.Request) (t T, err error)
- func BuildHandler[T any](f func(*http.Request) (t T, err error)) http.HandlerFunc
- func FromBodyAsJSON[T any](r *http.Request) (T, error)
- func Handler[I, O any](fromRequest func(*http.Request) (input I, err error), ...) http.HandlerFunc
- func StatusCode(v any) int
- func WriteResponse(w http.ResponseWriter, resp Response) (int64, error)
- type JSON
- type Response
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildHandler ¶
BuildHandler converts an ordinary function to a http.Handlerfunc, calling WriteSuccess(w, t) if there's no error and WriteError(w, err) if there is.
func FromBodyAsJSON ¶
FromBodyASJSON gets a T from the request body by calling json.NewDecoder.Decode.
func StatusCode ¶
StatusCode is a sensible default. If v implements interface{StatusCode() int}, or is an error that wraps something that does, Otherwise, if it's an error, use i
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, resp Response) (int64, error)
WriteResponse writes resp to the ResponseWriter.
Types ¶
Click to show internal directories.
Click to hide internal directories.