nrhttprouter

package
v3.23.0+incompatible Latest Latest
Warning

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

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

Documentation

Overview

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 (
	"fmt"
	"net/http"
	"os"

	"github.com/julienschmidt/httprouter"
	newrelic "github.com/newrelic/go-agent"
	"github.com/newrelic/go-agent/_integrations/nrhttprouter"
)

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) {
		w.Write([]byte("welcome\n"))
	})
	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/_integrations/nrhttprouter/example/main.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

type Router struct {
	*httprouter.Router
	// 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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