ppfasthttprouter

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

ppfasthttprouter

This package instruments the fasthttp/router package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/fasthttprouter
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/fasthttprouter"

Usage

PkgGoDev

This package instruments inbound requests handled by a fasthttp/router.Router. Use New() to trace all handlers:

r := ppfasthttprouter.New()
r.GET("/user/{name}", user)

For each request, a pinpoint.Tracer is stored in the request context. By using the pinpoint.FromContext function, this tracer can be obtained in your handler. Alternatively, the context of the request may be propagated where the context that contains the pinpoint.Tracer is required.

import (
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/fasthttp"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/fasthttprouter"
    "github.com/valyala/fasthttp"
)

func user(ctx *fasthttp.RequestCtx) {
    tracer := pinpoint.FromContext(ctx.UserValue(ppfasthttp.CtxKey).(context.Context))
    defer tracer.NewSpanEvent("f1").EndSpanEvent()

    fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name"))
}

func main() {
    ... //setup agent

    r := ppfasthttprouter.New()
    r.GET("/user/{name}", user)
    log.Fatal(fasthttp.ListenAndServe(":9000", r.Handler))
}

Full Example Source

This package supports URL Statistics feature. It aggregates response times, successes and failures for each router pattern.

Config Options

Documentation

Overview

Package ppfasthttprouter instruments the fasthttp/router package (https://github.com/fasthttp/router).

This package instruments inbound requests handled by a fasthttp/router.Router. Use New() to trace all handlers:

r := ppfasthttprouter.New()
r.GET("/", Index)
r.GET("/hello/:name", Hello)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

type Router struct {
	*router.Router
}

func New

func New() *Router

New returns a new Router which will instrument all added fasthttp/router.Router handlers.

func (*Router) ANY

func (r *Router) ANY(path string, handler fasthttp.RequestHandler)

func (*Router) CONNECT

func (r *Router) CONNECT(path string, handler fasthttp.RequestHandler)

func (*Router) DELETE

func (r *Router) DELETE(path string, handler fasthttp.RequestHandler)

func (*Router) GET

func (r *Router) GET(path string, handler fasthttp.RequestHandler)

func (*Router) HEAD

func (r *Router) HEAD(path string, handler fasthttp.RequestHandler)

func (*Router) Handle

func (r *Router) Handle(method, path string, handler fasthttp.RequestHandler)

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handler fasthttp.RequestHandler)

func (*Router) PATCH

func (r *Router) PATCH(path string, handler fasthttp.RequestHandler)

func (*Router) POST

func (r *Router) POST(path string, handler fasthttp.RequestHandler)

func (*Router) PUT

func (r *Router) PUT(path string, handler fasthttp.RequestHandler)

func (*Router) TRACE

func (r *Router) TRACE(path string, handler fasthttp.RequestHandler)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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