Files
geo/server/internal/shared/middleware/request_id.go
T
root b31d8d0096 feat(migrations): Harden task audit tracking and optimize article templates
- Added migration to harden task audit tracking by modifying audit_logs and related tables.
- Introduced operator_id to several tables for better tracking of actions.
- Updated article_templates with new prompt templates for various article types, enhancing content generation.
- Created prompt_rules and schedule_tasks tables to manage content generation rules and scheduling.
- Added foreign key constraints to articles for better data integrity.
2026-04-02 00:31:28 +08:00

41 lines
817 B
Go

package middleware
import (
"context"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
const RequestIDHeader = "X-Request-ID"
const requestIDKey = "request_id"
type requestIDContextKey struct{}
func RequestID() gin.HandlerFunc {
return func(c *gin.Context) {
rid := c.GetHeader(RequestIDHeader)
if rid == "" {
rid = uuid.New().String()
}
c.Set(requestIDKey, rid)
c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), requestIDContextKey{}, rid))
c.Header(RequestIDHeader, rid)
c.Next()
}
}
func RequestIDFromGin(c *gin.Context) string {
if rid, ok := c.Get(requestIDKey); ok {
return rid.(string)
}
return ""
}
func RequestIDFromContext(ctx context.Context) string {
if rid, ok := ctx.Value(requestIDContextKey{}).(string); ok {
return rid
}
return ""
}