Skip to content

Commit

Permalink
Remove custom config
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi committed Dec 16, 2024
1 parent 16f93d7 commit b05b051
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions backend/internal/middleware/request_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,7 @@ import (
"github.com/labstack/echo/v4/middleware"
)

// RequestIDConfig holds configuration for the request ID middleware
type RequestIDConfig struct {
// Generator is a function to generate request IDs
Generator func() string
// RequestHeader is the name of the header to read the request ID from
RequestHeader string
// ResponseHeader is the name of the header to write the request ID to
ResponseHeader string
}

// DefaultRequestIDConfig provides default configuration values
func DefaultRequestIDConfig() RequestIDConfig {
return RequestIDConfig{
Generator: nil, // will use echo's default uuid generator
RequestHeader: echo.HeaderXRequestID,
ResponseHeader: echo.HeaderXRequestID,
}
}

// RequestID returns a middleware that adds a request ID to the request context
func RequestID() echo.MiddlewareFunc {
return RequestIDWithConfig(DefaultRequestIDConfig())
}

// RequestIDWithConfig returns a middleware with custom configuration
func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFunc {
// convert our config to echo's middleware config
echoConfig := middleware.RequestIDConfig{
Generator: config.Generator,
RequestHeader: config.RequestHeader,
ResponseHeader: config.ResponseHeader,
}

return middleware.RequestIDWithConfig(echoConfig)
return middleware.RequestID()
}

0 comments on commit b05b051

Please sign in to comment.