-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiler.go
34 lines (28 loc) · 1.16 KB
/
profiler.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
package just
import "net/http"
// Profiler interface.
type IProfiler interface {
OnStartRequest(*http.Request) // Event start processing HTTP request.
OnSelectRoute(*http.Request, IRouteInfo) // Event select route for request.
OnWriteResponseData([]byte) // Event write data to response.
OnWriteResponseHeader(int, http.Header) // Event write headers to response.
Info(...interface{}) // Send info message to profiler.
Error(...interface{}) // Send error message to profiler.
Warning(...interface{}) // Send warning message to profiler.
Debug(...interface{}) // Send debug message to profiler.
}
type profiledResponseWriter struct {
writer http.ResponseWriter
profiler IProfiler
}
func (w *profiledResponseWriter) Write(data []byte) (int, error) {
defer w.profiler.OnWriteResponseData(data)
return w.writer.Write(data)
}
func (w *profiledResponseWriter) WriteHeader(status int) {
defer w.profiler.OnWriteResponseHeader(status, w.writer.Header())
w.writer.WriteHeader(status)
}
func (w *profiledResponseWriter) Header() http.Header {
return w.writer.Header()
}