v3.25.0 Latest Latest

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0 Imports: 4 Imported by: 0



Package nrhttprouter instruments applications.

Use this package to instrument inbound requests handled by a httprouter.Router. Use an *nrhttprouter.Router in place of your *httprouter.Router. Example:

package main

import (

	newrelic ""

func main() {
	cfg := newrelic.NewConfig("httprouter App", os.Getenv("NEW_RELIC_LICENSE_KEY"))
	app, _ := newrelic.NewApplication(cfg)

	// Create the Router replacement:
	router := nrhttprouter.New(app)

	router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	router.GET("/hello/:name", (w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		w.Write([]byte(fmt.Sprintf("hello %s\n", ps.ByName("name"))))
	http.ListenAndServe(":8000", router)

Runnable example:



This section is empty.


This section is empty.


This section is empty.


type Router

type Router struct {
	// contains filtered or unexported fields

Router should be used in place of httprouter.Router. Create it using New().

func New

func New(app newrelic.Application) *Router

New creates a new Router to be used in place of httprouter.Router.

func (*Router) DELETE

func (r *Router) DELETE(path string, h httprouter.Handle)

DELETE replaces httprouter.Router.DELETE.

func (*Router) GET

func (r *Router) GET(path string, h httprouter.Handle)

GET replaces httprouter.Router.GET.

func (*Router) HEAD

func (r *Router) HEAD(path string, h httprouter.Handle)

HEAD replaces httprouter.Router.HEAD.

func (*Router) Handle

func (r *Router) Handle(method, path string, h httprouter.Handle)

Handle replaces httprouter.Router.Handle.

func (*Router) Handler

func (r *Router) Handler(method, path string, handler http.Handler)

Handler replaces httprouter.Router.Handler.

func (*Router) HandlerFunc

func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)

HandlerFunc replaces httprouter.Router.HandlerFunc.

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, h httprouter.Handle)

OPTIONS replaces httprouter.Router.OPTIONS.

func (*Router) PATCH

func (r *Router) PATCH(path string, h httprouter.Handle)

PATCH replaces httprouter.Router.PATCH.

func (*Router) POST

func (r *Router) POST(path string, h httprouter.Handle)

POST replaces httprouter.Router.POST.

func (*Router) PUT

func (r *Router) PUT(path string, h httprouter.Handle)

PUT replaces httprouter.Router.PUT.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP replaces httprouter.Router.ServeHTTP.


Path Synopsis

Jump to

Keyboard shortcuts

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