From 08771c5267542b3bff17b06f750050076f53917b Mon Sep 17 00:00:00 2001 From: Kapil Verma Date: Wed, 23 Nov 2022 14:51:21 +0530 Subject: [PATCH] added method to route --- go/gorrila/mux/mux.go | 10 ++++++---- go/gorrila/mux/mux_test.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/go/gorrila/mux/mux.go b/go/gorrila/mux/mux.go index 5fbbb6fb..646fb942 100644 --- a/go/gorrila/mux/mux.go +++ b/go/gorrila/mux/mux.go @@ -1,6 +1,7 @@ package mux import ( + "fmt" "net/http" "github.com/google/sqlcommenter/go/core" @@ -10,13 +11,14 @@ import ( func SQLCommenterMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - route := mux.CurrentRoute(r) - pathTemplate, err := route.GetPathTemplate() + muxRoute := mux.CurrentRoute(r) + path, err := muxRoute.GetPathTemplate() if err != nil { - pathTemplate = "" + path = "" } - ctx := core.ContextInject(r.Context(), httpnet.NewHTTPRequestTags("gorrila/mux", pathTemplate, core.GetFunctionName(route.GetHandler()))) + route := fmt.Sprintf("%s--%s", r.Method, path) + ctx := core.ContextInject(r.Context(), httpnet.NewHTTPRequestTags("gorrila/mux", route, core.GetFunctionName(muxRoute.GetHandler()))) h.ServeHTTP(w, r.WithContext(ctx)) }) } diff --git a/go/gorrila/mux/mux_test.go b/go/gorrila/mux/mux_test.go index 9283603f..c17d2985 100644 --- a/go/gorrila/mux/mux_test.go +++ b/go/gorrila/mux/mux_test.go @@ -11,7 +11,7 @@ import ( func TestSQLCommenterMiddleware(t *testing.T) { framework := "gorrila/mux" - route := "/test/{id}" + route := "GET--/test/{id}" action := "github.com/google/sqlcommenter/go/gorrila/mux.TestSQLCommenterMiddleware.func1" mockHandler := func(w http.ResponseWriter, r *http.Request) {