-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathresponseWriter.go
38 lines (31 loc) · 1.14 KB
/
responseWriter.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
package middleware
import (
"net/http"
)
// LoggedResponseWriter - wraps http.ResponseWriter.
// Supports the ability to read a previously recorded response status.
type LoggedResponseWriter struct {
responseWriter http.ResponseWriter
status int
}
// Header returns the result of calling the Header() method of the wrapped http.ResponseWriter.
func (lrw *LoggedResponseWriter) Header() http.Header {
return lrw.responseWriter.Header()
}
// Write returns the result of calling the Write() method of the wrapped http.ResponseWriter.
func (lrw *LoggedResponseWriter) Write(data []byte) (int, error) {
return lrw.responseWriter.Write(data)
}
// WriteHeader returns the result of calling the WriteHeader() method of the wrapped http.ResponseWriter
func (lrw *LoggedResponseWriter) WriteHeader(status int) {
lrw.status = status
lrw.responseWriter.WriteHeader(status)
}
// Status - returns the previously recorded response status.
func (lrw *LoggedResponseWriter) Status() int {
return lrw.status
}
// ResponseWriter returns wrapped ResponseWriter.
func (lrw *LoggedResponseWriter) ResponseWriter() http.ResponseWriter {
return lrw.responseWriter
}