github.com/julienschmidt/httprouter
A high performance HTTP request router that scales well.
Add fields to httprouter.Router
Definition of
httprouter.Router
Introduce new declarations:
// Using the following synthetic imports:
import (
tracing "gopkg.in/DataDog/dd-trace-go.v1/contrib/julienschmidt/httprouter/internal/tracing"
)
type __dd_wRouter struct {
*Router
}
func __dd_wrapRouter(r *Router) tracing.Router {
return &__dd_wRouter{r}
}
func (w __dd_wRouter) Lookup(method string, path string) (any, []tracing.Param, bool) {
h, params, ok := w.Router.Lookup(method, path)
return h, __dd_wrapParams(params), ok
}
type __dd_wParam struct {
Param
}
func __dd_wrapParams(params Params) []tracing.Param {
wParams := make([]tracing.Param, len(params))
for i, p := range params {
wParams[i] = __dd_wParam{p}
}
return wParams
}
func (w __dd_wParam) GetKey() string {
return w.Key
}
func (w __dd_wParam) GetValue() string {
return w.Value
}
func __dd_init(r *Router) {
if r.__dd_config != nil {
return
}
r.__dd_config = tracing.NewConfig()
return
}
Trace httprouter.Router#ServeHTTP
Function body
- Function declaration
- Is method of
*httprouter.Router
- Function name
ServeHTTP
Prepend statements produced by the following template:
// Using the following synthetic imports:
import (
tracing "gopkg.in/DataDog/dd-trace-go.v1/contrib/julienschmidt/httprouter/internal/tracing"
)
{{- $r := .Function.Receiver -}}
{{- $w := .Function.Argument 0 -}}
{{- $req := .Function.Argument 1 -}}
__dd_init({{ $r }})
tw, treq, afterHandle, handled := tracing.BeforeHandle({{ $r }}.__dd_config, {{ $r }}, __dd_wrapRouter, {{ $w }}, {{ $req }})
{{ $w }} = tw
{{ $req }} = treq
defer afterHandle()
if handled {
return
}