httptreemux

package
v1.999.0-beta.12 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package httptreemux provides functions to trace the dimfeld/httptreemux/v5 package (https://github.com/dimfeld/httptreemux).

Package httptreemux provides functions to trace the dimfeld/httptreemux/v5 package (https://github.com/dimfeld/httptreemux).

Example
package main

import (
	"fmt"
	"log"
	"net/http"

	httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/dimfeld/httptreemux.v5"
)

func Index(w http.ResponseWriter, _ *http.Request, _ map[string]string) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, _ *http.Request, params map[string]string) {
	fmt.Fprintf(w, "hello, %s!\n", params["name"])
}

func main() {
	router := httptrace.New()
	router.GET("/", Index)
	router.GET("/hello/:name", Hello)

	log.Fatal(http.ListenAndServe(":8080", router))
}
Output:

Example (WithServiceName)
package main

import (
	"fmt"
	"log"
	"net/http"

	httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/dimfeld/httptreemux.v5"
)

func Index(w http.ResponseWriter, _ *http.Request, _ map[string]string) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, _ *http.Request, params map[string]string) {
	fmt.Fprintf(w, "hello, %s!\n", params["name"])
}

func main() {
	router := httptrace.New(httptrace.WithServiceName("http.router"))
	router.GET("/", Index)
	router.GET("/hello/:name", Hello)

	log.Fatal(http.ListenAndServe(":8080", router))
}
Output:

Example (WithSpanOpts)
package main

import (
	"fmt"
	"log"
	"net/http"

	httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/dimfeld/httptreemux.v5"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func Index(w http.ResponseWriter, _ *http.Request, _ map[string]string) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, _ *http.Request, params map[string]string) {
	fmt.Fprintf(w, "hello, %s!\n", params["name"])
}

func main() {
	router := httptrace.New(
		httptrace.WithServiceName("http.router"),
		httptrace.WithSpanOptions(
			tracer.Tag(ext.SamplingPriority, ext.PriorityUserKeep),
		),
	)

	router.GET("/", Index)
	router.GET("/hello/:name", Hello)

	log.Fatal(http.ListenAndServe(":8080", router))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextRouter

type ContextRouter = v2.ContextRouter

ContextRouter is a traced version of httptreemux.ContextMux.

func NewWithContext

func NewWithContext(opts ...RouterOption) *ContextRouter

NewWithContext returns a new router augmented with tracing and preconfigured to work with context objects. The matched route and parameters are added to the context.

type Router

type Router = v2.Router

Router is a traced version of httptreemux.TreeMux.

func New

func New(opts ...RouterOption) *Router

New returns a new router augmented with tracing.

type RouterOption

type RouterOption = v2.RouterOption

RouterOption represents an option that can be passed to New.

func WithResourceNamer

func WithResourceNamer(namer func(router *httptreemux.TreeMux, w http.ResponseWriter, req *http.Request) string) RouterOption

WithResourceNamer specifies a function which will be used to obtain the resource name for a given request.

func WithServiceName

func WithServiceName(name string) RouterOption

WithServiceName sets the given service name for the returned router.

func WithSpanOptions

func WithSpanOptions(opts ...ddtrace.StartSpanOption) RouterOption

WithSpanOptions applies the given set of options to the span started by the router.

Jump to

Keyboard shortcuts

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