From 28879b02fb8c55ac43d636df2843b091f000972e Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Fri, 9 May 2025 20:26:22 +0800 Subject: [PATCH] fix --- app/main/api/desc/front/product.api | 1 - app/main/api/internal/handler/routes.go | 17 +++++++---------- .../middleware/global/reqHeaderCtxMiddleware.go | 14 +++----------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/app/main/api/desc/front/product.api b/app/main/api/desc/front/product.api index 9565820..0818d03 100644 --- a/app/main/api/desc/front/product.api +++ b/app/main/api/desc/front/product.api @@ -26,7 +26,6 @@ service main { @server ( prefix: api/v1/product group: product - middleware: SourceInterceptor ) service main { @handler GetProductRenderList diff --git a/app/main/api/internal/handler/routes.go b/app/main/api/internal/handler/routes.go index 047a764..0540091 100644 --- a/app/main/api/internal/handler/routes.go +++ b/app/main/api/internal/handler/routes.go @@ -304,16 +304,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { ) server.AddRoutes( - rest.WithMiddlewares( - []rest.Middleware{serverCtx.SourceInterceptor}, - []rest.Route{ - { - Method: http.MethodGet, - Path: "/render_list/:module", - Handler: product.GetProductRenderListHandler(serverCtx), - }, - }..., - ), + []rest.Route{ + { + Method: http.MethodGet, + Path: "/render_list/:module", + Handler: product.GetProductRenderListHandler(serverCtx), + }, + }, rest.WithPrefix("/api/v1/product"), ) diff --git a/app/main/api/internal/middleware/global/reqHeaderCtxMiddleware.go b/app/main/api/internal/middleware/global/reqHeaderCtxMiddleware.go index c9a15c4..9cca1c8 100644 --- a/app/main/api/internal/middleware/global/reqHeaderCtxMiddleware.go +++ b/app/main/api/internal/middleware/global/reqHeaderCtxMiddleware.go @@ -5,14 +5,6 @@ import ( "net/http" ) -type contextKey string - -const ( - brandKey contextKey = "brand" - platformKey contextKey = "platform" - promoteKey contextKey = "promoteKey" -) - func ReqHeaderCtxMiddleware(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { brand := r.Header.Get("X-Brand") @@ -20,13 +12,13 @@ func ReqHeaderCtxMiddleware(next http.HandlerFunc) http.HandlerFunc { promoteValue := r.Header.Get("X-Promote-Key") ctx := r.Context() if brand != "" { - ctx = context.WithValue(ctx, brandKey, brand) + ctx = context.WithValue(ctx, "brand", brand) } if platform != "" { - ctx = context.WithValue(ctx, platformKey, platform) + ctx = context.WithValue(ctx, "platform", platform) } if promoteValue != "" { - ctx = context.WithValue(ctx, promoteKey, promoteValue) + ctx = context.WithValue(ctx, "promoteKey", promoteValue) } r = r.WithContext(ctx) next(w, r)