Skip to content

Commit 08771c5

Browse files
committed
added method to route
1 parent 9ae8338 commit 08771c5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

go/gorrila/mux/mux.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mux
22

33
import (
4+
"fmt"
45
"net/http"
56

67
"github.com/google/sqlcommenter/go/core"
@@ -10,13 +11,14 @@ import (
1011

1112
func SQLCommenterMiddleware(h http.Handler) http.Handler {
1213
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13-
route := mux.CurrentRoute(r)
14-
pathTemplate, err := route.GetPathTemplate()
14+
muxRoute := mux.CurrentRoute(r)
15+
path, err := muxRoute.GetPathTemplate()
1516
if err != nil {
16-
pathTemplate = ""
17+
path = ""
1718
}
1819

19-
ctx := core.ContextInject(r.Context(), httpnet.NewHTTPRequestTags("gorrila/mux", pathTemplate, core.GetFunctionName(route.GetHandler())))
20+
route := fmt.Sprintf("%s--%s", r.Method, path)
21+
ctx := core.ContextInject(r.Context(), httpnet.NewHTTPRequestTags("gorrila/mux", route, core.GetFunctionName(muxRoute.GetHandler())))
2022
h.ServeHTTP(w, r.WithContext(ctx))
2123
})
2224
}

go/gorrila/mux/mux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestSQLCommenterMiddleware(t *testing.T) {
1313
framework := "gorrila/mux"
14-
route := "/test/{id}"
14+
route := "GET--/test/{id}"
1515
action := "github.com/google/sqlcommenter/go/gorrila/mux.TestSQLCommenterMiddleware.func1"
1616

1717
mockHandler := func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)