- 修复depguard错误:为ops service文件添加redis导入例外 - 修复errcheck错误:添加错误检查和类型断言检查 - 修复gofmt错误:格式化代码 - 修复ineffassign错误:移除无效的idx++赋值 - 修复staticcheck错误:合并条件赋值 - 修复unused错误:移除未使用的字段和函数 - ops_cleanup_service.go: entryID字段 - ops_retry.go: status字段 - ops_upstream_context.go: getOpsUpstreamErrors函数
31 lines
697 B
Go
31 lines
697 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ClientRequestID ensures every request has a unique client_request_id in request.Context().
|
|
//
|
|
// This is used by the Ops monitoring module for end-to-end request correlation.
|
|
func ClientRequestID() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if c.Request == nil {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
if v := c.Request.Context().Value(ctxkey.ClientRequestID); v != nil {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
id := uuid.New().String()
|
|
c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), ctxkey.ClientRequestID, id))
|
|
c.Next()
|
|
}
|
|
}
|