github.com/julienschmidt/httprouter

github.com/julienschmidt/httprouter

A high performance HTTP request router that scales well.

Add fields to httprouter.Router

Join Point
Definition of httprouter.Router
Advice
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
}
Advice
Add new field __dd_config of type *tracing.Config.

Trace httprouter.Router#ServeHTTP

Join Point
Function body
Advice
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
}