Avoid checking date header of web requests by properly applying generic handlers (#2914)

This commit is contained in:
Anis Elleuch
2016-10-12 20:58:36 +01:00
committed by Harshavardhana
parent 73982c8cb6
commit df59967f59
13 changed files with 965 additions and 13 deletions
+35
View File
@@ -0,0 +1,35 @@
package negroni
import (
"log"
"net/http"
"os"
"time"
)
// ALogger interface
type ALogger interface {
Println(v ...interface{})
Printf(format string, v ...interface{})
}
// Logger is a middleware handler that logs the request as it goes in and the response as it goes out.
type Logger struct {
// ALogger implements just enough log.Logger interface to be compatible with other implementations
ALogger
}
// NewLogger returns a new Logger instance
func NewLogger() *Logger {
return &Logger{log.New(os.Stdout, "[negroni] ", 0)}
}
func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
start := time.Now()
l.Printf("Started %s %s", r.Method, r.URL.Path)
next(rw, r)
res := rw.(ResponseWriter)
l.Printf("Completed %v %s in %v", res.Status(), http.StatusText(res.Status()), time.Since(start))
}