How to use kcd.Handler
The kcd.Handler takes a function (which is your handler) and a default status code.
It returns a normal standard http.HandlerFuncso you can use it with classic routers.
r.Get("/superman", kcd.Handler(YourMagicHandler, http.StatusOK))YourMagicHandler is a handler of your application, this is where the magic happens!
Construct your handler
Function parameters accepted
context.Context
http.ResponseWriter
*http.Request
Your custom input struct as a pointer
Function return
Your custom output (could be either a pointer or non-pointer type)
error
Additional information
The minimal signature of your function looks like this:
func MagicHandler() errorThe maximal signature of your function may look like this:
func MagicHandler(ctx context.Context, res http.ResponseWriter, req *http.Request, in *MyInput) (out MyOutpput, err error)All inputs parameters can be omitted
The order of inputs parameters is not important
The Input (represented as
in *MyInput) must be a pointerThe order of the return must be preserved with the error as the last parameter
Exception
You can use the standard http handler.
Compatible with the standard libraryLast updated
Was this helpful?