http

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Example
package main

import (
	"net/http"

	httptrace "github.com/DataDog/dd-trace-go/contrib/net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Hello World!\n"))
}

func main() {
	mux := httptrace.NewServeMux("web-service", nil)
	mux.HandleFunc("/", handler)
	http.ListenAndServe(":8080", mux)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriter is a small wrapper around an http response writer that will intercept and store the status of a request. It implements the ResponseWriter interface.

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter, span *tracer.Span) *ResponseWriter

New ResponseWriter allocateds and returns a new ResponseWriter.

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(b []byte) (int, error)

Write writes the data to the connection as part of an HTTP reply. We explicitely call WriteHeader with the 200 status code in order to get it reported into the span.

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(status int)

WriteHeader sends an HTTP response header with status code. It also sets the status code to the span.

type ServeMux

type ServeMux struct {
	*http.ServeMux
	*tracer.Tracer
	// contains filtered or unexported fields
}

ServeMux is an HTTP request multiplexer that traces all the incoming requests.

func NewServeMux

func NewServeMux(service string, t *tracer.Tracer) *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL. We only needed to rewrite this method to be able to trace the multiplexer.

Jump to

Keyboard shortcuts

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