requestid

package module
v0.0.0-...-39ac581 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Overview

Package requestid contains functions to handle an id for the current request.

The idea is to read the current id from the received request and pass it to downstream services in order to get a trace across service boundaries.

Logstatements should log the request id in every statement to correlate the statements to a specific request. This simplifies the tracking of a request through a system which serves multiple concurrent requests.

Example:

func main() {
	mux := http.NewServeMux()
	mux.Handle("/hello", requestid.AddToCtx()(helloHandler()))
}

func helloHandler() http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// get id from context
		rid,_ := requestid.FromCtx(r.Context())
	})
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToCtx

func AddToCtx() func(http.Handler) http.Handler

AddToCtx reads the requestid http header x-dv-request-id from the current request and stores the id in the context.

If the request doesn't have an existing id a new one is generated.

func FromCtx

func FromCtx(ctx context.Context) (string, error)

FromCtx reads the current request id from the context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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