add tysc handlers to kontor-gin
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/gin-contrib/slog"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func RequestID() gin.HandlerFunc {
|
||||
func RequestID(skipPaths []string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
logger := slog.Get(c)
|
||||
id := c.GetHeader("X-Request-ID")
|
||||
if id == "" {
|
||||
id = uuid.NewString()
|
||||
}
|
||||
if len(skipPaths) > 0 && !slices.Contains(skipPaths, c.Request.URL.Path) {
|
||||
logger.Info("RequestID", "id", id)
|
||||
}
|
||||
c.Set("request_id", id)
|
||||
c.Writer.Header().Set("X-Request-ID", id)
|
||||
c.Next()
|
||||
|
||||
Reference in New Issue
Block a user