requestid

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHeaderName = "X-Request-Id"

DefaultHeaderName 是默认的 HTTP 请求标识请求头。

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) string

FromContext 从上下文读取请求标识,不存在时返回空字符串。

func Server

func Server(opts ...Option) middleware.Middleware

Server 创建适用于 Kratos HTTP Server 的请求标识中间件。

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID 将请求标识写入上下文。

Types

type HandlerMiddleware

type HandlerMiddleware func(http.Handler) http.Handler

HandlerMiddleware 定义 HTTP 请求标识中间件类型。

func Middleware

func Middleware(opts ...Option) HandlerMiddleware

Middleware 创建提取或生成请求标识的 HTTP 中间件,并将标识写回响应头。

type Option

type Option func(*options)

Option 配置 HTTP 请求标识中间件。

func WithHeaderName

func WithHeaderName(name string) Option

WithHeaderName 设置提取和写入请求标识的 HTTP 请求头。

func WithIDGenerator

func WithIDGenerator(fn func() string) Option

WithIDGenerator 设置自定义请求标识生成函数。

Jump to

Keyboard shortcuts

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