Documentation ¶
Overview ¶
Package hnyhttprouter has Middleware to use with the httprouter muxer.
Summary ¶
hnyhttprouter has Middleware to wrap individual handlers, and is best used in conjunction with the nethttp WrapHandler function. Using these two together will get you an event for every request that comes through your application while also decorating the most interesting paths (the handlers that you wrap) with additional fields from the httprouter patterns.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(handle httprouter.Handle) httprouter.Handle
Middleware wraps httprouter handlers. Since it wraps handlers with explicit parameters, it can add those values to the event it generates.
Example ¶
// assume you have handlers named hello and index var hello func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) var index func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) router := httprouter.New() // call regular httprouter Handles with wrappers to extract parameters router.GET("/hello/:name", Middleware(hello)) // though the wrapper also works on routes that don't have parameters router.GET("/", Middleware(index)) // wrap the main router to set everything up for instrumenting log.Fatal(http.ListenAndServe(":8080", hnynethttp.WrapHandler(router)))
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.