requestid

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const DefaultHeader = header.XRequestID

DefaultHeader is the default request, response header

Variables

This section is empty.

Functions

This section is empty.

Types

type RequestID

type RequestID struct {
	// TrustProxy trusts request id from request header
	// sets TrustProxy to false for always generate new request id
	TrustProxy bool

	// Header is the http header key
	Header string
}

RequestID middleware

Example

At the edge, do not trust a client-supplied request ID: always mint a new one so callers cannot spoof or poison the value used in logs and upstream headers. A custom header key is used here instead of the default X-Request-Id.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/requestid"
)

func main() {
	s := parapet.New()
	s.Use(&requestid.RequestID{
		TrustProxy: false,
		Header:     "X-Trace-Id",
	})
}

func New

func New() *RequestID

New creates default req id middleware

Example

Assign every request a unique ID. New trusts an incoming X-Request-Id from an upstream proxy (reusing it for distributed tracing) and otherwise generates a fresh UUIDv4. The ID is written to both the request and response headers and recorded as "requestId" in the structured access log.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/requestid"
)

func main() {
	s := parapet.New()
	s.Use(requestid.New())
	// s.Use(upstream.SingleHost(...)) — the ID is forwarded to the upstream.
}

func (RequestID) ServeHandler

func (m RequestID) ServeHandler(h http.Handler) http.Handler

ServeHandler implements middleware interface

Jump to

Keyboard shortcuts

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