Created
July 27, 2014 06:53
-
-
Save ciaranarcher/abccf50cb37645ca27fa to your computer and use it in GitHub Desktop.
Revisions
-
ciaranarcher created this gist
Jul 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ // Create our own MyResponseWriter to wrap a standard http.ResponseWriter // so we can store the status code. type MyResponseWriter struct { status int http.ResponseWriter } func NewMyResponseWriter(res http.ResponseWriter) *MyResponseWriter { // Default the status code to 200 return &MyResponseWriter{200, res} } // Give a way to get the status func (w MyResponseWriter) Status() int { return w.status } // Satisfy the http.ResponseWriter interface func (w MyResponseWriter) Header() http.Header { return w.ResponseWriter.Header() } func (w MyResponseWriter) Write(data []byte) (int, error) { return w.ResponseWriter.Write(data) } func (w MyResponseWriter) WriteHeader(statusCode int) { // Store the status code w.status = statusCode // Write the status code onward. w.ResponseWriter.WriteHeader(statusCode) }