Created
June 23, 2019 08:18
-
-
Save tonespy/354953e3102b37498a0ca5273aac0ae0 to your computer and use it in GitHub Desktop.
API Logger
This file contains hidden or 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 app | |
import ( | |
"log" | |
"net/http" | |
"time" | |
"github.com/julienschmidt/httprouter" | |
) | |
// Logger :- An helper function for logging | |
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