Simplify bodyWriter write method using io.Copy#76
Conversation
Refactor write handling in bodyWriter to use io.Copy for simplicity.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #76 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 4 4
Lines 404 372 -32
=====================================
+ Misses 404 372 -32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Refactors bodyWriter.ReadFrom in dump.go to rely on io.Copy instead of maintaining a custom copy loop, simplifying response body capture while preserving the ability to delegate to the underlying gin.ResponseWriter when possible.
Changes:
- Removed the custom buffered copy loop and replaced it with
io.Copy(with a wrapper to avoidio.ReaderFromrecursion). - Deleted the now-unneeded
errInvalidWriteerror value.
Comments suppressed due to low confidence (1)
dump.go:19
- After removing
errInvalidWrite, theerrorsimport in this file becomes unused, which will cause the package to fail to compile. Please remove theerrorsimport (or reintroduce a use if needed).
gin.ResponseWriter
body *bytes.Buffer
maxSize int
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| break | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
io.Copy(struct{ io.Writer }{w}, r) intentionally wraps w to hide the io.ReaderFrom method (otherwise io.Copy would dispatch back to ReadFrom and recurse). Please add a short comment or use a named wrapper type to make this non-obvious requirement clearer and prevent accidental simplification to io.Copy(w, r) later.
| // Wrap w to hide its ReadFrom method and avoid infinite recursion via io.Copy. |
Refactor write handling in bodyWriter to use io.Copy for simplicity.
poke @schnoddelbotz