requestid

package
v0.1.0-beta-007 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const Key key = 0

Key is the key that holds the unique request ID in a request context.

Variables

View Source
var UUID = InheritOrGenerate("X-Request-Id", func(r *http.Request) string {
	return uuid.New().String()
})

UUID is a middleware which will inherit a request ID from the X-Request-ID header from an incoming HTTP request or otherwise generate a new UUID and store it in the request's context.

Functions

func InheritOrGenerate

func InheritOrGenerate(headerName string, factory FactoryFunc) func(http.Handler) http.Handler

InheritOrGenerate is a middleware which stores a unique request ID into the context of each incoming HTTP request. Use headerName to specify the HTTP header from which an already existing request ID should be inherited (e.g. X-Correlation-Id or X-Request-Id). If no request ID has been sent with the incoming HTTP request then a new request ID will be generated by calling the RequestIDFactoryFunc.

func Retrieve

func Retrieve(ctx context.Context) string

Retrieve returns a previously stored request ID from the given context. Returns "" if a request ID cannot be found.

Types

type FactoryFunc

type FactoryFunc func(r *http.Request) string

FactoryFunc generates a unique request ID based on an incoming HTTP request.

Jump to

Keyboard shortcuts

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