Documentation
¶
Overview ¶
Package exthttp supports setup of HTTP servers to implement the *Kit contracts. To keep the resulting binary small the net/http server is used.
Index ¶
- func GetterAsHandler[T any](handler func() T) func(w http.ResponseWriter, r *http.Request, body []byte)
- func LogRequest(next func(w http.ResponseWriter, r *http.Request, body []byte)) http.HandlerFunc
- func PanicRecovery(next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc
- func RegisterHttpHandler(path string, handler func(w http.ResponseWriter, r *http.Request, body []byte))
- func WriteBody(w http.ResponseWriter, response any)
- func WriteError(w http.ResponseWriter, err extension_kit.ExtensionError)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetterAsHandler ¶
func GetterAsHandler[T any](handler func() T) func(w http.ResponseWriter, r *http.Request, body []byte)
GetterAsHandler turns a getter function into a handler function. Typically used in combination with the RegisterHttpHandler function.
func LogRequest ¶
func LogRequest(next func(w http.ResponseWriter, r *http.Request, body []byte)) http.HandlerFunc
func PanicRecovery ¶
func PanicRecovery(next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc
func RegisterHttpHandler ¶
func RegisterHttpHandler(path string, handler func(w http.ResponseWriter, r *http.Request, body []byte))
RegisterHttpHandler registers a handler for the given path. Also adds panic recovery and request logging around the handler.
func WriteBody ¶
func WriteBody(w http.ResponseWriter, response any)
WriteBody writes the given value as the HTTP response body as JSON with status code 200.
func WriteError ¶
func WriteError(w http.ResponseWriter, err extension_kit.ExtensionError)
WriteError writes the error as the HTTP response body with status code 500.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.