[BUG] Middleware printing out "map[]"
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
I am new to API development in GOLANG, and I am trying to set up a simple "hello world" api to get started. It should just have one endpoint that will return a string message when hit. I have a custom middleware function that prints out the method, time taken for request, the host, and the url path. When I test things out, the custom middleware executes correctly but in the following line, "map[]" is printed out. Upon further debugging, I can't seem to figure out where this erronious print is coming from.
Expected Behavior
This "map[]" string should not print out. I just want to see the fstring implemented in the middleware handler.
Steps To Reproduce
With the following code for router setup: package main
import ( "calculator-api/calculator" "log" "net/http" "time"
"github.com/gorilla/mux"
)
func main() { router := mux.NewRouter() router.HandleFunc("/health", calculator.Alive).Methods("GET") port := ":8080" log.Printf("Server started on http://localhost%s", port)
if err := http.ListenAndServe(port, router); err != nil {
log.Fatal(err)
}
}
func loggingMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() log.Printf("[%s] %s %s %s", r.Method, time.Since(start), r.Host, r.URL.Path) next.ServeHTTP(w, r) }) }`,
And the following endpoint handler: import ( "fmt" "net/http"
"github.com/gorilla/mux"
)
//Simple health check endpoint func alive(w http.ResponseWriter,r *http.Request) { vars := mux.Vars(r) w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Response: %v\n", vars["message"]) } `, simply execute Go run, and hit the endpoint using curl/postman
Anything else?
No response
Source: gorilla/mux