forked from couchbaselabs/showfast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
access.go
43 lines (34 loc) · 835 Bytes
/
access.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"net/http"
log "gopkg.in/inconshreveable/log15.v2"
)
type ResponseWriterWrapper struct {
rw http.ResponseWriter
status int
}
func (r *ResponseWriterWrapper) Write(p []byte) (int, error) {
return r.rw.Write(p)
}
func (r *ResponseWriterWrapper) Header() http.Header {
return r.rw.Header()
}
func (r *ResponseWriterWrapper) WriteHeader(status int) {
r.status = status
r.rw.WriteHeader(status)
}
func accessLog(handler http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
log.Info("Received request",
"method", req.Method,
"path", req.URL.Path,
)
rww := ResponseWriterWrapper{rw, 200}
handler.ServeHTTP(&rww, req)
log.Info("Processed request",
"method", req.Method,
"path", req.URL.Path,
"status", rww.status,
)
})
}