middleware

package
v3.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectUserAgentLanguage added in v3.0.1

func DetectUserAgentLanguage() gin.HandlerFunc

DetectUserAgentLanguage 检测客户端语言

通过解析请求头中的`Accept-Language`字段得到

默认为`en`

func LogTrace added in v3.0.3

func LogTrace() gin.HandlerFunc

LogTrace 日志追踪

作用是在请求入口注入必要的内容到上下文,供后续的请求调用链使用,一般用于日志追踪、链路追踪

注入内容:

1.请求id

2.请求到来那一刻的纳秒时间戳

3.包装了请求id的日志组件实例

Example:

requestId, ok := ginContext.Get("requestId").(string)

spanId, ok := ginContext.Get("spanId").(string)

entryAt, ok := ginContext.Get("entryAt").(int64)

logger, ok := ginContext.Get("logger").(*zap.Logger)

func PrintRequestPayload

func PrintRequestPayload() gin.HandlerFunc

PrintRequestPayload 打印请求载荷

func PrometheusExporter

func PrometheusExporter() gin.HandlerFunc

PrometheusExporter 导出Prometheus指标

func WithCors

func WithCors(headers map[string]string) gin.HandlerFunc

WithCors 允许浏览器跨域请求

func WithCorsOnlyOptions added in v3.0.3

func WithCorsOnlyOptions(headers map[string]string) gin.HandlerFunc

WithCorsOnlyOptions 允许浏览器跨域请求

仅对options探测请求注入放行headers

Types

This section is empty.

Jump to

Keyboard shortcuts

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