Open mikepc opened 5 years ago
func logger() midfunc {
return func(next httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
start := time.Now()
// Initialize the status to 200 in case WriteHeader is not called
sw := statusRecorder{w, 200}
next(&sw, r, ps)
log.Printf("[%s: %s :%d] [time: %v]\n", r.Method, r.URL.String(), sw.status, time.Since(start))
return
}
}
}
For some reason the request's response object is nil, even when using defer.
How do I log the status code the endpoint resulted with?