hnyhttprouter

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 10

README

Documentation available via godoc

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL