/
response_writer.go
37 lines (30 loc) · 941 Bytes
/
response_writer.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
package web
import "net/http"
// StubResponseWriter wraps the standard http.ResponseWriter allowing for more
// verbose logging
type StubResponseWriter struct {
status int
size int
}
// Status provides an easy way to retrieve the status code
func (w *StubResponseWriter) Status() int {
return w.status
}
// Size provides an easy way to retrieve the response size in bytes
func (w *StubResponseWriter) Size() int {
return w.size
}
// Header returns & satisfies the http.ResponseWriter interface
func (w *StubResponseWriter) Header() http.Header {
return make(http.Header)
}
// Write satisfies the http.ResponseWriter interface and
// captures data written, in bytes
func (w *StubResponseWriter) Write(_ []byte) (int, error) {
return 0, nil
}
// WriteHeader satisfies the http.ResponseWriter interface and
// allows us to catch the status code
func (w *StubResponseWriter) WriteHeader(statusCode int) {
w.status = statusCode
}