constants

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TraceIDKey trace ID 在 context 中的 key
	TraceIDKey = "trace_id"
	// RequestIDKey request ID 在 context 中的 key
	RequestIDKey = "request_id"
)

Trace and Request ID 相关常量

View Source
const (
	// TraceIDHeader trace ID 的 HTTP 头名称
	TraceIDHeader = "X-Trace-ID"
	// RequestIDHeader request ID 的 HTTP 头名称
	RequestIDHeader = "X-Request-ID"
)

HTTP headers for trace and request IDs

Variables

This section is empty.

Functions

func GenerateID

func GenerateID() string

GenerateID 生成随机的 ID(用于 trace id 和 request id)

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext 从 context 中提取 request ID

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

TraceIDFromContext 从 context 中提取 trace ID

func WithRequestID

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

WithRequestID 将 request ID 添加到 context 中

func WithTraceAndRequestID

func WithTraceAndRequestID(ctx context.Context, traceID, requestID string) context.Context

WithTraceAndRequestID 同时将 trace ID 和 request ID 添加到 context 中

func WithTraceID

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID 将 trace ID 添加到 context 中

Types

This section is empty.

Jump to

Keyboard shortcuts

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