requestid

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

README

RequestID

Middleware to generates id for every incoming request.

Usage

Import

import "github.com/ngamux/middleware/requestid"

Instance With Default Config

reqidMiddleware := requestid.New()

Instance With Custom Config

reqidMiddleware := requestid.New(
	requestid.WithKeyHeader(func() string { return "X-Request-ID" }),
	requestid.WithID(func() string {
		_id, _ := uuid.NewV7()
		return _id.String()
	}),
)

Mount Instance to Ngamux

Global Middleware
mux := ngamux.New()
mux.Use(reqidMiddleware)
Route Middleware
mux := ngamux.New()
mux.Get("/", reqidMiddleware(handler))

or

mux := ngamux.New()
mux.Get("/", ngamux.WithMiddlewares(reqidMiddleware)(handler))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...func(*config)) func(http.HandlerFunc) http.HandlerFunc

func WithID

func WithID(id func() string) func(*config)

func WithKeyHeader

func WithKeyHeader(key func() string) func(*config)

Types

This section is empty.

Jump to

Keyboard shortcuts

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