b31d8d0096
- 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.
41 lines
817 B
Go
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 ""
|
|
}
|