-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
41 lines (33 loc) · 879 Bytes
/
log.go
File metadata and controls
41 lines (33 loc) · 879 Bytes
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
// Copyright (c) David Capello. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.txt file.
package htex
import (
"log"
"net/http"
"time"
)
type logResponseWriter struct {
w http.ResponseWriter
code int
}
func (w *logResponseWriter) Header() http.Header {
return w.w.Header()
}
func (w *logResponseWriter) Write(p []byte) (int, error) {
return w.w.Write(p)
}
func (w *logResponseWriter) WriteHeader(statusCode int) {
w.code = statusCode
w.w.WriteHeader(statusCode)
}
type LogHtexHandler struct {
handler http.Handler
w logResponseWriter
}
func (h *LogHtexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()
h.w = logResponseWriter{w: w, code: 200}
h.handler.ServeHTTP(&h.w, r)
log.Println(" -> response code", h.w.code, "time", time.Since(start))
}