@@ -14,6 +14,7 @@ import (
1414 "io"
1515 "net"
1616 "net/http"
17+ "time"
1718)
1819
1920// MakeRecorder returns a RecordingResponseWriter which wraps around the
@@ -41,6 +42,8 @@ type RecordingResponseWriter interface {
4142 http.Flusher
4243 Status () int
4344 Size () int
45+ GetTimeStamp () time.Time
46+ SetTimeStamp (time.Time )
4447}
4548
4649// responseRecorder is wrapper of http.ResponseWriter that keeps track of its HTTP
@@ -49,12 +52,15 @@ type responseRecorder struct {
4952 w http.ResponseWriter
5053 status int
5154 size int
55+ ts time.Time
5256}
5357
58+ // Header implements http.ResponseWriter
5459func (l * responseRecorder ) Header () http.Header {
5560 return l .w .Header ()
5661}
5762
63+ // Write implements http.ResponseWriter
5864func (l * responseRecorder ) Write (b []byte ) (int , error ) {
5965 if l .status == 0 {
6066 // The status will be StatusOK if WriteHeader has not been called yet
@@ -65,11 +71,30 @@ func (l *responseRecorder) Write(b []byte) (int, error) {
6571 return size , err
6672}
6773
74+ // WriteHeader implements http.ResponseWriter
6875func (l * responseRecorder ) WriteHeader (s int ) {
6976 l .w .WriteHeader (s )
7077 l .status = s
7178}
7279
80+ // GetTimeStamp returns the timestamp
81+ // This can be used to store a starttime for a request and return it
82+ // after the request is done.
83+ // It is not go-routine safe.
84+ func (l * responseRecorder ) GetTimeStamp () (tout time.Time ) {
85+ tout = l .ts
86+ return
87+ }
88+
89+ // SetTimeStamp sets a timestamp.
90+ // This can be used to store a starttime for a request and return it
91+ // after the request is done.
92+ // It is not go-routine safe.
93+ func (l * responseRecorder ) SetTimeStamp (tin time.Time ) {
94+ l .ts = tin
95+ }
96+
97+
7398// Status returns the http status of the written request.
7499func (l * responseRecorder ) Status () int {
75100 return l .status
0 commit comments