beeline-go: github.com/honeycombio/beeline-go/wrappers/hnyhttprouter Index | Examples | Files

package hnyhttprouter

import "github.com/honeycombio/beeline-go/wrappers/hnyhttprouter"

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

Package Files

doc.go httprouter.go

func Middleware Uses

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.

Code:

// 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)))

Package hnyhttprouter imports 5 packages (graph) and is imported by 1 packages. Updated 2019-03-22. Refresh now. Tools for package owners.