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
+5 -5
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v5"
)
// ErrorResponse represents a standardized error response
@@ -50,7 +50,7 @@ func NewHTTPError(code int, message string, err error) *HTTPError {
}
// RespondWithError sends a standardized error response
func RespondWithError(c echo.Context, code int, message string, err error) error {
func RespondWithError(c *echo.Context, code int, message string, err error) error {
response := ErrorResponse{
Error: message,
Message: "",
@@ -66,7 +66,7 @@ func RespondWithError(c echo.Context, code int, message string, err error) error
}
// RespondWithHTTPError sends an HTTPError as JSON
func RespondWithHTTPError(c echo.Context, httpErr *HTTPError) error {
func RespondWithHTTPError(c *echo.Context, httpErr *HTTPError) error {
response := ErrorResponse{
Error: httpErr.Message,
}
@@ -79,8 +79,8 @@ func RespondWithHTTPError(c echo.Context, httpErr *HTTPError) error {
}
// WrapHandler wraps an echo.HandlerFunc to return standardized errors
func WrapHandler(fn func(c echo.Context) error) echo.HandlerFunc {
return func(c echo.Context) error {
func WrapHandler(fn func(*echo.Context) error) echo.HandlerFunc {
return func(c *echo.Context) error {
err := fn(c)
if err != nil {
if httpErr, ok := err.(*HTTPError); ok {