diff --git a/activityPub.go b/activityPub.go index 9cc4823..06bc37b 100644 --- a/activityPub.go +++ b/activityPub.go @@ -9,7 +9,6 @@ import ( "encoding/pem" "errors" "fmt" - "io" "log" "net/http" "net/url" @@ -255,13 +254,11 @@ func (a *goBlog) apGetRemoteActor(iri string) (*asPerson, int, error) { } defer resp.Body.Close() if !apRequestIsSuccess(resp.StatusCode) { - _, _ = io.Copy(io.Discard, resp.Body) return nil, resp.StatusCode, nil } actor := &asPerson{} err = json.NewDecoder(resp.Body).Decode(actor) if err != nil { - _, _ = io.Copy(io.Discard, resp.Body) return nil, 0, err } return actor, 0, nil diff --git a/activityPubSending.go b/activityPubSending.go index 1a7af32..0011ee8 100644 --- a/activityPubSending.go +++ b/activityPubSending.go @@ -122,8 +122,6 @@ func (a *goBlog) apSendSigned(blogIri, to string, activity []byte) error { if !apRequestIsSuccess(resp.StatusCode) { body, _ := io.ReadAll(resp.Body) return fmt.Errorf("signed request failed with status %d: %s", resp.StatusCode, string(body)) - } else { - _, _ = io.Copy(io.Discard, resp.Body) } return nil } diff --git a/blogroll.go b/blogroll.go index dfe931f..b53e914 100644 --- a/blogroll.go +++ b/blogroll.go @@ -3,7 +3,6 @@ package main import ( "bytes" "fmt" - "io" "log" "net/http" "sort" @@ -77,10 +76,7 @@ func (a *goBlog) getBlogrollOutlines(blog string) ([]*opml.Outline, error) { if err != nil { return nil, err } - defer func() { - _, _ = io.Copy(io.Discard, res.Body) - res.Body.Close() - }() + defer res.Body.Close() if code := res.StatusCode; code < 200 || 300 <= code { return nil, fmt.Errorf("opml request not successful, status code: %d", code) } diff --git a/check.go b/check.go index 942b291..c441b2b 100644 --- a/check.go +++ b/check.go @@ -98,7 +98,6 @@ func (a *goBlog) checkLinks(w io.Writer, posts ...*post) error { if err != nil { return nil, err } - _, _ = io.Copy(io.Discard, resp.Body) _ = resp.Body.Close() // Cache result sm.Store(link.Second, resp.StatusCode) diff --git a/geo.go b/geo.go index 9664975..f131078 100644 --- a/geo.go +++ b/geo.go @@ -55,10 +55,7 @@ func (a *goBlog) photonReverse(lat, lon float64, lang string) ([]byte, error) { if err != nil { return nil, err } - defer func() { - _, _ = io.Copy(io.Discard, resp.Body) - _ = resp.Body.Close() - }() + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("response status code: %v", resp.StatusCode) } diff --git a/healthcheck.go b/healthcheck.go index 0d7c557..d229314 100644 --- a/healthcheck.go +++ b/healthcheck.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "io" "log" "net/http" "time" @@ -27,7 +26,6 @@ func (a *goBlog) healthcheck() bool { return false } defer resp.Body.Close() - _, _ = io.Copy(io.Discard, resp.Body) return resp.StatusCode == 200 } diff --git a/mediaCompression.go b/mediaCompression.go index b516f42..43efbf8 100644 --- a/mediaCompression.go +++ b/mediaCompression.go @@ -81,12 +81,10 @@ func (sp *shortpixel) compress(url string, upload mediaStorageSaveFunc, hc httpC } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - _, _ = io.Copy(io.Discard, resp.Body) return "", fmt.Errorf("shortpixel failed to compress image, status code %d", resp.StatusCode) } tmpFile, err := os.CreateTemp("", "tiny-*."+fileExtension) if err != nil { - _, _ = io.Copy(io.Discard, resp.Body) return "", err } defer func() { @@ -94,7 +92,6 @@ func (sp *shortpixel) compress(url string, upload mediaStorageSaveFunc, hc httpC _ = os.Remove(tmpFile.Name()) }() if _, err = io.Copy(tmpFile, resp.Body); err != nil { - _, _ = io.Copy(io.Discard, resp.Body) return "", err } fileName, err := getSHA256(tmpFile) @@ -133,7 +130,6 @@ func (tf *tinify) compress(url string, upload mediaStorageSaveFunc, hc httpClien return "", err } defer resp.Body.Close() - _, _ = io.Copy(io.Discard, resp.Body) if resp.StatusCode != http.StatusCreated { return "", fmt.Errorf("failed to compress image, status code %d", resp.StatusCode) } @@ -161,12 +157,10 @@ func (tf *tinify) compress(url string, upload mediaStorageSaveFunc, hc httpClien } defer downloadResp.Body.Close() if downloadResp.StatusCode != http.StatusOK { - _, _ = io.Copy(io.Discard, downloadResp.Body) return "", fmt.Errorf("tinify failed to resize image, status code %d", downloadResp.StatusCode) } tmpFile, err := os.CreateTemp("", "tiny-*."+fileExtension) if err != nil { - _, _ = io.Copy(io.Discard, downloadResp.Body) return "", err } defer func() { @@ -174,7 +168,6 @@ func (tf *tinify) compress(url string, upload mediaStorageSaveFunc, hc httpClien _ = os.Remove(tmpFile.Name()) }() if _, err = io.Copy(tmpFile, downloadResp.Body); err != nil { - _, _ = io.Copy(io.Discard, downloadResp.Body) return "", err } fileName, err := getSHA256(tmpFile) @@ -208,12 +201,10 @@ func (cf *cloudflare) compress(url string, upload mediaStorageSaveFunc, hc httpC } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - _, _ = io.Copy(io.Discard, resp.Body) return "", fmt.Errorf("cloudflare failed to compress image, status code %d", resp.StatusCode) } tmpFile, err := os.CreateTemp("", "tiny-*."+fileExtension) if err != nil { - _, _ = io.Copy(io.Discard, resp.Body) return "", err } defer func() { @@ -221,7 +212,6 @@ func (cf *cloudflare) compress(url string, upload mediaStorageSaveFunc, hc httpC _ = os.Remove(tmpFile.Name()) }() if _, err = io.Copy(tmpFile, resp.Body); err != nil { - _, _ = io.Copy(io.Discard, resp.Body) return "", err } fileName, err := getSHA256(tmpFile) diff --git a/telegram.go b/telegram.go index bbd106b..87e07f0 100644 --- a/telegram.go +++ b/telegram.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "io" "log" "net/http" "net/url" @@ -75,7 +74,6 @@ func (a *goBlog) send(tg *configTelegram, message, mode string) error { return err } defer resp.Body.Close() - _, _ = io.Copy(io.Discard, resp.Body) if resp.StatusCode != http.StatusOK { return fmt.Errorf("failed to send Telegram message, status code %d", resp.StatusCode) } diff --git a/tts.go b/tts.go index b9586bb..5eb1f80 100644 --- a/tts.go +++ b/tts.go @@ -161,10 +161,7 @@ func (a *goBlog) downloadTTSAudio(ctx context.Context, lang, text, outputFile st if err != nil { return err } - defer func() { - _, _ = io.Copy(io.Discard, res.Body) - _ = res.Body.Close() - }() + defer res.Body.Close() if res.StatusCode != http.StatusOK { return fmt.Errorf("TTS: got status: %s, text: %s", res.Status, text) } diff --git a/webmentionSending.go b/webmentionSending.go index a6839f2..f532ebd 100644 --- a/webmentionSending.go +++ b/webmentionSending.go @@ -84,7 +84,6 @@ func (a *goBlog) sendWebmention(endpoint, source, target string) error { return err } defer res.Body.Close() - _, _ = io.Copy(io.Discard, res.Body) if code := res.StatusCode; code < 200 || 300 <= code { return fmt.Errorf("response error: %v", res.StatusCode) } @@ -104,12 +103,10 @@ func (a *goBlog) discoverEndpoint(urlStr string) string { } defer resp.Body.Close() if code := resp.StatusCode; code < 200 || 300 <= code { - _, _ = io.Copy(io.Discard, resp.Body) return "" } endpoint, err := extractEndpoint(resp) if err != nil || endpoint == "" { - _, _ = io.Copy(io.Discard, resp.Body) return "" } if urls, err := resolveURLReferences(urlStr, endpoint); err == nil && len(urls) > 0 && urls[0] != "" { diff --git a/webmentionVerification.go b/webmentionVerification.go index c8717a9..0a65b77 100644 --- a/webmentionVerification.go +++ b/webmentionVerification.go @@ -96,7 +96,6 @@ func (a *goBlog) verifyMention(m *mention) error { } } err = m.verifyReader(resp.Body) - _, _ = io.Copy(io.Discard, resp.Body) _ = resp.Body.Close() if err != nil { _, err := a.db.exec("delete from webmentions where source = @source and target = @target", sql.Named("source", m.Source), sql.Named("target", m.Target))