lint: check deferred resp.Body.Close error returns
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

golangci-lint v2 (errcheck) flagged three unchecked resp.Body.Close()
returns in gitea.go and vault.go. Wrap each deferred Close in a closure
discarding the return, the idiomatic form for a deferred Close whose
error is intentionally ignored.
This commit is contained in:
2026-08-12 21:46:40 +10:00
parent fa8ccac0dd
commit 8403741902
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ func (c *GiteaClient) do(method, path string, body any, out any) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
data, _ := io.ReadAll(resp.Body)
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("gitea %s %s: HTTP %d: %s", method, path, resp.StatusCode, strings.TrimSpace(string(data)))
+2 -2
View File
@@ -29,7 +29,7 @@ func approleLogin(vaultAddr, roleID string) (string, error) {
if err != nil {
return "", fmt.Errorf("vault approle login: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
data, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("vault approle login: HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(data)))
@@ -62,7 +62,7 @@ func readGiteaCreds(vaultAddr, clientToken string) (string, error) {
if err != nil {
return "", fmt.Errorf("vault read %s: %w", GiteaCredsPath, err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
data, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("vault read %s: HTTP %d: %s", GiteaCredsPath, resp.StatusCode, strings.TrimSpace(string(data)))