correlationid

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 2 Imported by: 0

README

Correlation ID Middleware

What it does

Propagates or creates a correlation ID so a single business transaction can be followed across services.

How to implement

package main

import (
	"github.com/oarkflow/fh"
	"github.com/oarkflow/fh/mw/correlationid"
)

func main() {
	app := fh.New()
	app.Use(correlationid.New(correlationid.Config{Header: "X-Correlation-ID"}))

	app.Get("/", func(c fh.Ctx) error {
		return c.Status(fh.StatusOK).SendString("ok")
	})
}

Impact

Very small overhead. Greatly improves debugging across distributed systems.

Ordering guidance

Run at the beginning of the chain before logging, tracing, audit, proxy, and handlers.

Production considerations

Validate externally provided IDs to avoid log injection. Forward the correlation ID to downstream services.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) fh.HandlerFunc

Types

type Config

type Config struct {
	Header   string
	LocalKey string

	// TrustIncoming controls whether a client-supplied correlation ID header
	// is accepted (subject to MaxIncomingLength and Validator) instead of
	// always generating a fresh one. It defaults to true when New is called
	// with no Config at all; once a Config value is passed, TrustIncoming is
	// honored exactly as set (Go's normal zero-value semantics), so pass
	// TrustIncoming: true explicitly if a partial Config should keep trusting
	// incoming IDs.
	TrustIncoming     bool
	Generator         requestid.Generator
	Validator         requestid.Validator
	MaxIncomingLength int
}

Jump to

Keyboard shortcuts

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