refactor(middleware): fix type signatures for Echo v5 compatibility

Update all middleware functions to use *echo.Context (pointer) instead of echo.Context (value) as required by Echo v5.

Changes in device_auth.go:
- Update DeviceAuthMiddleware() signature (line 38)
- Update validateDeviceAuth() signature (line 170)
- Update RequireDeviceAuth() signature (line 212)

Changes in error_handler.go:
- Update RespondWithError() signature (line 44)
- Update RespondWithHTTPError() signature (line 69)
- Update WrapHandler() to accept *echo.Context (line 82)
- Fix context passing in WrapHandler() (c is already pointer)

Changes in rate_limiter.go:
- Update RateLimiterMiddleware() signature (line 102)

Changes in request_tracing.go:
- Update RequestTracingMiddleware() signature (line 48)
- Fix Response() dereference for v5 API (line 264)
  - Use *c.Response() to get http.ResponseWriter

Changes in security.go:
- Update SecurityHeadersMiddleware() signature (line 14)

Changes in device_auth_test.go:
- Update test helper signatures

Changes in middleware_test.go:
- Remove unused import

All middleware now properly implements Echo v5's pointer-based context pattern.
This commit is contained in:
2026-03-06 14:00:05 -05:00
parent abb090ef64
commit 0438ec4625
7 changed files with 25 additions and 26 deletions
+6 -6
View File
@@ -5,13 +5,13 @@ import (
"strconv"
"strings"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v5"
)
// SecurityHeadersMiddleware adds security headers to all responses
func SecurityHeadersMiddleware() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
return func(c *echo.Context) error {
// Add security headers
c.Response().Header().Set("X-Content-Type-Options", "nosniff")
c.Response().Header().Set("X-Frame-Options", "DENY")
@@ -30,7 +30,7 @@ func SecurityHeadersMiddleware() echo.MiddlewareFunc {
// NOTE: Disabled for Docker self-hosted deployments - SSL is handled by reverse proxy
func HTTPSRedirectMiddleware(httpsPort string) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
return func(c *echo.Context) error {
// SSL is handled by proxy - no redirect needed
return next(c)
}
@@ -38,7 +38,7 @@ func HTTPSRedirectMiddleware(httpsPort string) echo.MiddlewareFunc {
}
// isTestMode checks if the application is running in test mode
func isTestMode(c echo.Context) bool {
func isTestMode(c *echo.Context) bool {
// Check for test mode header or environment
return c.Request().Header.Get("X-Test-Mode") == "true" ||
c.Request().Header.Get("X-Forwarded-Proto") == "http"
@@ -49,7 +49,7 @@ func isTestMode(c echo.Context) bool {
// This middleware reads X-Forwarded-Proto and X-Forwarded-Host headers set by the proxy
func SSLProxyMiddleware() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
return func(c *echo.Context) error {
// Check for proxy headers
if proto := c.Request().Header.Get("X-Forwarded-Proto"); proto == "https" {
c.Request().URL.Scheme = "https"
@@ -113,7 +113,7 @@ func NewSecureCORSConfig() CORSSecurityConfig {
// SecureCORSMiddleware creates CORS middleware with security
func SecureCORSMiddleware(config CORSSecurityConfig) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
return func(c *echo.Context) error {
origin := c.Request().Header.Get("Origin")
// Check if origin is allowed