1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-09 16:10:01 +00:00
mondash/logResponseWriter.go
2015-07-06 22:49:05 +02:00

40 lines
1 KiB
Go

package main
import "net/http"
// LogResponseWriter wraps the standard http.ResponseWritter allowing for more
// verbose logging
type LogResponseWriter struct {
Status int
Size int
http.ResponseWriter
}
// NewLogResponseWriter instanciates a new LogResponseWriter
func NewLogResponseWriter(res http.ResponseWriter) *LogResponseWriter {
// Default the status code to 200
return &LogResponseWriter{200, 0, res}
}
// Header returns & satisfies the http.ResponseWriter interface
func (w *LogResponseWriter) Header() http.Header {
return w.ResponseWriter.Header()
}
// Write satisfies the http.ResponseWriter interface and
// captures data written, in bytes
func (w *LogResponseWriter) Write(data []byte) (int, error) {
written, err := w.ResponseWriter.Write(data)
w.Size += written
return written, err
}
// WriteHeader satisfies the http.ResponseWriter interface and
// allows us to cach the status code
func (w *LogResponseWriter) WriteHeader(statusCode int) {
w.Status = statusCode
w.ResponseWriter.WriteHeader(statusCode)
}