Skip to content

Commit

Permalink
Added RequestIDHeader config value to Middleware configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Nov 16, 2022
1 parent 9e95dc7 commit 645fc89
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (

type (
Config struct {
Logger *Logger
Skipper middleware.Skipper
RequestIDKey string
NestKey string
Logger *Logger
Skipper middleware.Skipper
RequestIDHeader string
RequestIDKey string
NestKey string
}

Context struct {
Expand Down Expand Up @@ -47,6 +48,10 @@ func Middleware(config Config) echo.MiddlewareFunc {
config.RequestIDKey = "id"
}

if config.RequestIDHeader == "" {
config.RequestIDHeader = echo.HeaderXRequestID
}

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if config.Skipper(c) {
Expand All @@ -58,10 +63,10 @@ func Middleware(config Config) echo.MiddlewareFunc {
res := c.Response()
start := time.Now()

id := req.Header.Get(echo.HeaderXRequestID)
id := req.Header.Get(config.RequestIDHeader)

if id == "" {
id = res.Header().Get(echo.HeaderXRequestID)
id = res.Header().Get(config.RequestIDHeader)
}

logger := config.Logger
Expand Down

0 comments on commit 645fc89

Please sign in to comment.