Help us shape the future of Go! Take the 2026 Go Developer Survey

requestid

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package requestid gives every request an identifier, reusing the one the client or an upstream proxy sent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(c *zinc.Context) string

Get returns the request's identifier. Without the middleware, it falls back to the X-Request-ID request header.

func New

func New(configs ...Config) zinc.Middleware

New reuses the request's identifier or generates one, and mirrors it into both the request and the response headers.

func Random

func Random(*zinc.Context) (string, error)

Random returns a 128-bit cryptographically random hexadecimal identifier.

Types

type Config

type Config struct {
	// Header carries the identifier on the request and the response.
	Header string
	// Generate creates identifiers. Nil uses Random.
	Generate Generator
}

Config controls the header and identifier generation. The zero value uses X-Request-ID and random 128-bit identifiers.

type Generator

type Generator func(*zinc.Context) (string, error)

Generator creates an identifier when the request does not carry one.

func Static

func Static(id string) Generator

Static returns a generator that always answers id, for tests.

Jump to

Keyboard shortcuts

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