1
0
mirror of https://github.com/Luzifer/mondash.git synced 2024-09-19 17:02:58 +00:00
mondash/logResponseWriter.go

41 lines
1.0 KiB
Go
Raw Normal View History

2015-07-06 20:48:54 +00:00
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)
}