Skip to content

Commit

Permalink
Merge pull request #197 from google/gorrila/mux/gorrila/mux
Browse files Browse the repository at this point in the history
added method to route in SQLCommenterMiddleware
  • Loading branch information
kapv89 committed Nov 23, 2022
2 parents 9ae8338 + 08771c5 commit b356ba9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions go/gorrila/mux/mux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mux

import (
"fmt"
"net/http"

"github.com/google/sqlcommenter/go/core"
Expand All @@ -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))
})
}
2 changes: 1 addition & 1 deletion go/gorrila/mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b356ba9

Please sign in to comment.