From 908eb9b63124a6684f276e7930d8bc6783b861bf Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 18 Dec 2018 22:24:20 -0600 Subject: [PATCH] lint: shadow err and defes on close with no err check --- backend/app/cmd/cleanup.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/app/cmd/cleanup.go b/backend/app/cmd/cleanup.go index f6411c8a..3b1119dc 100644 --- a/backend/app/cmd/cleanup.go +++ b/backend/app/cmd/cleanup.go @@ -42,8 +42,8 @@ func (cc *CleanupCommand) Execute(args []string) error { totalComments, spamComments := 0, 0 for _, post := range posts { - comments, err := cc.listComments(post.URL) - if err != nil { + comments, e := cc.listComments(post.URL) + if e != nil { continue } for _, comment := range comments { @@ -105,7 +105,7 @@ func (cc *CleanupCommand) listPosts() ([]store.PostInfo, error) { if err != nil { return nil, errors.Wrapf(err, "get request failed for list of posts, site %s", cc.Site) } - defer r.Body.Close() + defer func() { _ = r.Body.Close() }() if r.StatusCode != 200 { return nil, errors.Errorf("request %s failed with status %d", listURL, r.StatusCode) @@ -133,13 +133,15 @@ func (cc *CleanupCommand) listComments(postURL string) ([]store.Comment, error) return nil, errors.Wrapf(err, "get request failed for comments, %s", postURL) } if r.StatusCode == http.StatusTooManyRequests { - r.Body.Close() + _ = r.Body.Close() time.Sleep(500 * time.Millisecond) continue } break } + defer func() { _ = r.Body.Close() }() + if r.StatusCode != http.StatusOK { return nil, errors.Errorf("request %s failed with status %d", commentsURL, r.StatusCode) } @@ -169,7 +171,7 @@ func (cc *CleanupCommand) deleteComment(c store.Comment) error { if err != nil { return errors.Wrapf(err, "delete request failed for comment %s, %s", c.ID, c.Locator.URL) } - defer r.Body.Close() + defer func() { _ = r.Body.Close() }() if r.StatusCode != http.StatusOK { return errors.Errorf("delete request failed with status %s", r.Status) }