go-agent: github.com/newrelic/go-agent/v3/integrations/nrhttprouter Index | Files | Directories

package nrhttprouter

import "github.com/newrelic/go-agent/v3/integrations/nrhttprouter"

Package nrhttprouter instruments https://github.com/julienschmidt/httprouter 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 "github.com/newrelic/go-agent/v3/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: https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrhttprouter/example/main.go


Package Files


type Router Uses

type Router struct {
    // contains filtered or unexported fields

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

func New Uses

func New(app *newrelic.Application) *Router

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

func (*Router) DELETE Uses

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

DELETE replaces httprouter.Router.DELETE.

func (*Router) GET Uses

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

GET replaces httprouter.Router.GET.

func (*Router) HEAD Uses

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

HEAD replaces httprouter.Router.HEAD.

func (*Router) Handle Uses

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

Handle replaces httprouter.Router.Handle.

func (*Router) Handler Uses

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

Handler replaces httprouter.Router.Handler.

func (*Router) HandlerFunc Uses

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

HandlerFunc replaces httprouter.Router.HandlerFunc.

func (*Router) OPTIONS Uses

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

OPTIONS replaces httprouter.Router.OPTIONS.

func (*Router) PATCH Uses

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

PATCH replaces httprouter.Router.PATCH.

func (*Router) POST Uses

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

POST replaces httprouter.Router.POST.

func (*Router) PUT Uses

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

PUT replaces httprouter.Router.PUT.

func (*Router) ServeHTTP Uses

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

ServeHTTP replaces httprouter.Router.ServeHTTP.



Package nrhttprouter imports 4 packages (graph) and is imported by 1 packages. Updated 2020-07-02. Refresh now. Tools for package owners.