requestid

package
v0.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

MetadataKey 是 gRPC 请求标识使用的 metadata 键。 gRPC 底层传输会将 metadata 键规范化为小写,但对外保持该名称不变。

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 gRPC Server 的请求标识中间件。

func StreamServerInterceptor

func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

StreamServerInterceptor 创建提取 metadata 请求标识的流式服务端拦截器。

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

UnaryServerInterceptor 创建提取 metadata 请求标识并写入上下文的一元服务端拦截器。

func WithRequestID

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

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

Types

type Option

type Option func(*options)

Option 配置 gRPC 请求标识拦截器。

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