From 0826df6957b6bd93e7accfac8a8dc0311a99cd77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:39:35 +0000 Subject: [PATCH 1/4] Initial plan From 876023d362a890e04485b989f2522c88f71ded55 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:42:10 +0000 Subject: [PATCH 2/4] Fix errcheck linting error by checking w.Write return values Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com> --- internal/handlers/blog.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/handlers/blog.go b/internal/handlers/blog.go index 160804a..427e5cd 100644 --- a/internal/handlers/blog.go +++ b/internal/handlers/blog.go @@ -165,6 +165,12 @@ func (h *BlogHandler) Feed(w http.ResponseWriter, r *http.Request) { return } - w.Write([]byte(xml.Header)) - w.Write(data) + if _, err := w.Write([]byte(xml.Header)); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + if _, err := w.Write(data); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } From 4ffb31c0b8553fb14f2aa5d04b7e437a1ac9ff37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:43:00 +0000 Subject: [PATCH 3/4] Address code review feedback: combine writes and use generic error messages Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com> --- internal/handlers/blog.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/handlers/blog.go b/internal/handlers/blog.go index 427e5cd..91f0693 100644 --- a/internal/handlers/blog.go +++ b/internal/handlers/blog.go @@ -161,16 +161,15 @@ func (h *BlogHandler) Feed(w http.ResponseWriter, r *http.Request) { data, err := xml.MarshalIndent(feed, "", " ") if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } - if _, err := w.Write([]byte(xml.Header)); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - if _, err := w.Write(data); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + // Combine header and data into a single write to avoid partial writes + output := append([]byte(xml.Header), data...) + if _, err := w.Write(output); err != nil { + // Cannot send error response after w.Write has been called + // Log the error if needed return } } From 5e267b193d3be2cc98316e0eb97ff82803133ff7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:43:38 +0000 Subject: [PATCH 4/4] Optimize slice allocation with pre-sized capacity Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com> --- internal/handlers/blog.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/handlers/blog.go b/internal/handlers/blog.go index 91f0693..9df1770 100644 --- a/internal/handlers/blog.go +++ b/internal/handlers/blog.go @@ -166,7 +166,9 @@ func (h *BlogHandler) Feed(w http.ResponseWriter, r *http.Request) { } // Combine header and data into a single write to avoid partial writes - output := append([]byte(xml.Header), data...) + output := make([]byte, 0, len(xml.Header)+len(data)) + output = append(output, []byte(xml.Header)...) + output = append(output, data...) if _, err := w.Write(output); err != nil { // Cannot send error response after w.Write has been called // Log the error if needed