From 254102bfacce4801b48cc081e86b72c4b968aa80 Mon Sep 17 00:00:00 2001 From: Hein Date: Sun, 1 Mar 2026 12:08:36 +0200 Subject: [PATCH] refactor(auth): simplify handler type assertions for middleware --- pkg/resolvespec/resolvespec.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/resolvespec/resolvespec.go b/pkg/resolvespec/resolvespec.go index 70c75ee..16be359 100644 --- a/pkg/resolvespec/resolvespec.go +++ b/pkg/resolvespec/resolvespec.go @@ -70,17 +70,17 @@ func SetupMuxRoutes(muxRouter *mux.Router, handler *Handler, authMiddleware Midd entityWithIDPath := buildRoutePath(schema, entity) + "/{id}" // Create handler functions for this specific entity - postEntityHandler := createMuxHandler(handler, schema, entity, "") - postEntityWithIDHandler := createMuxHandler(handler, schema, entity, "id") - getEntityHandler := createMuxGetHandler(handler, schema, entity, "") + var postEntityHandler http.Handler = createMuxHandler(handler, schema, entity, "") + var postEntityWithIDHandler http.Handler = createMuxHandler(handler, schema, entity, "id") + var getEntityHandler http.Handler = createMuxGetHandler(handler, schema, entity, "") optionsEntityHandler := createMuxOptionsHandler(handler, schema, entity, []string{"GET", "POST", "OPTIONS"}) optionsEntityWithIDHandler := createMuxOptionsHandler(handler, schema, entity, []string{"POST", "OPTIONS"}) // Apply authentication middleware if provided if authMiddleware != nil { - postEntityHandler = authMiddleware(postEntityHandler).(http.HandlerFunc) - postEntityWithIDHandler = authMiddleware(postEntityWithIDHandler).(http.HandlerFunc) - getEntityHandler = authMiddleware(getEntityHandler).(http.HandlerFunc) + postEntityHandler = authMiddleware(postEntityHandler) + postEntityWithIDHandler = authMiddleware(postEntityWithIDHandler) + getEntityHandler = authMiddleware(getEntityHandler) // Don't apply auth middleware to OPTIONS - CORS preflight must not require auth }