weather/pkg/logger/writer.go

26 lines
486 B
Go
Raw Normal View History

package logger
import "net/http"
//ResponseWriter ResponseWriter
type ResponseWriter struct {
http.ResponseWriter
Status int
Length int
}
//WriteHeader override `http.ResponseWriter` memorize status code
func (w *ResponseWriter) WriteHeader(status int) {
w.Status = status
w.ResponseWriter.WriteHeader(status)
}
func (w *ResponseWriter) Write(b []byte) (int, error) {
if w.Status == 0 {
w.Status = 200
}
n, err := w.ResponseWriter.Write(b)
w.Length += n
return n, err
}