Last active
April 28, 2021 02:30
-
-
Save kasuganosora/80ea91960d0f8343bfe2a397145da191 to your computer and use it in GitHub Desktop.
Dump ResponseWriter
This file contains 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 characters
type ResponseDumpWriter struct { | |
Body bytes.Buffer | |
Headers []string | |
w http.ResponseWriter | |
statusCode int | |
} | |
func (w *ResponseDumpWriter)Header()http.Header { | |
return w.w.Header() | |
} | |
func (w *ResponseDumpWriter)Write(b []byte)(int, error){ | |
w.Body.Write(b) | |
return w.w.Write(b) | |
} | |
func (w *ResponseDumpWriter)WriteHeader(statusCode int){ | |
w.statusCode = statusCode | |
w.w.WriteHeader(statusCode) | |
} | |
func (w *ResponseDumpWriter)Dump(){ | |
fmt.Println("Response: ") | |
fmt.Printf("Status code: %d\n", w.statusCode) | |
fmt.Println("Headers: ") | |
for key,values := range w.w.Header() { | |
fmt.Printf("Key %s, Value: %s\n", key, strings.Join(values, ", ")) | |
} | |
fmt.Println("Body: ") | |
fmt.Println( w.Body.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment