reqid

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reqid gives each HTTP request a relay-minted ULID, echoes it as X-Relay-Request-ID, and carries it with a request-scoped logger in the context. A caller's X-Request-ID is carried separately as the client id.

Index

Constants

View Source
const (
	HeaderInbound  = "X-Request-Id"
	HeaderOutbound = "X-Relay-Request-Id"
)

Variables

This section is empty.

Functions

func ClientID added in v0.10.1

func ClientID(ctx context.Context) string

ClientID returns the caller's own X-Request-ID, empty when absent or invalid.

func From

func From(ctx context.Context) string

func Generate

func Generate() string

func Logger

func Logger(ctx context.Context) *slog.Logger

func Middleware

func Middleware(base *slog.Logger) func(http.Handler) http.Handler

Middleware always mints the request id: it keys stored records, so a caller must not be able to choose or repeat it. A valid inbound X-Request-ID is kept apart as the client id and echoed back unchanged.

func WithNewID added in v0.10.1

func WithNewID(ctx context.Context, base *slog.Logger) context.Context

WithNewID derives a context carrying a freshly minted id, for requests multiplexed over one HTTP request (one WebSocket connection).

Types

This section is empty.

Jump to

Keyboard shortcuts

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