You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
617 B
26 lines
617 B
package middlewares
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.devices.local/mawas/golang-api-skeleton/lib/common"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func RequestID() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
requestID := c.Request.Header.Get(viper.GetString("application.requestIDHeaderName"))
|
|
if requestID == "" {
|
|
id, err := common.NewGUID()
|
|
if err != nil {
|
|
// FIXME log request id creation error
|
|
fmt.Println("ERROR request id creation in middleware")
|
|
}
|
|
requestID = id.String()
|
|
}
|
|
c.Set("requestID", requestID)
|
|
c.Writer.Header().Set("X-Request-Id", requestID)
|
|
c.Next()
|
|
}
|
|
}
|