Created
September 30, 2017 16:17
-
-
Save gsingharoy/6a10ec0d827c142d719311256a646d52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"time" | |
"github.com/julienschmidt/httprouter" | |
) | |
// A Logger function which simply wraps the handler function around some log messages | |
func Logger(fn func(w http.ResponseWriter, r *http.Request, param httprouter.Params)) func(w http.ResponseWriter, r *http.Request, param httprouter.Params) { | |
return func(w http.ResponseWriter, r *http.Request, param httprouter.Params) { | |
start := time.Now() | |
log.Printf("%s %s", r.Method, r.URL.Path) | |
fn(w, r, param) | |
log.Printf("Done in %v (%s %s)", time.Since(start), r.Method, r.URL.Path) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment