import lab3 files

This commit is contained in:
Голиков Maximillian Антон
2026-10-18 21:14:01 +03:00
parent ec540a1a72
commit 76322040e5
64 changed files with 4446 additions and 0 deletions
@@ -0,0 +1,32 @@
package middleware
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
const (
RequestIDKey = "request_id"
RequestIDHeader = "X-Request-Id"
)
func RequestID() gin.HandlerFunc {
return func(c *gin.Context) {
id := c.GetHeader(RequestIDHeader)
if id == "" {
id = uuid.NewString()
}
c.Set(RequestIDKey, id)
c.Writer.Header().Set(RequestIDHeader, id)
c.Next()
}
}
func GetRequestID(c *gin.Context) string {
if v, ok := c.Get(RequestIDKey); ok {
if s, ok := v.(string); ok {
return s
}
}
return ""
}