Chore: Refactor error handling and resource management across multiple files (golangci-lint)

- Updated error handling to use the error return value for resource closures in tests and functions, ensuring proper error reporting.
- Replaced direct calls to `Close()` with deferred functions that handle errors gracefully.
- Improved readability by using `strings.ReplaceAll` instead of `strings.Replace` for string manipulation.
- Enhanced network connection handling by adding default cases for unsupported network types.
- Updated HTTP response handling to use the appropriate status codes and error messages.
- Removed unused variables and commented-out code to clean up the codebase.
This commit is contained in:
Ralph Slooten
2025-06-22 10:32:03 +12:00
parent 429d2e2b3a
commit f99d9ecf69
35 changed files with 250 additions and 232 deletions

View File

@@ -193,10 +193,10 @@ func downloadToBytes(url string) ([]byte, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != 200 {
err := fmt.Errorf("Error downloading %s", url)
err := fmt.Errorf("error downloading %s", url)
return nil, err
}

View File

@@ -152,13 +152,14 @@ func (c CanIEmail) getTest(k string) (Warning, error) {
s.Platform = platform
s.Version = version
if support == "y" {
switch support {
case "y":
y++
s.Support = "yes"
} else if support == "n" {
case "n":
n++
s.Support = "no"
} else {
default:
p++
s.Support = "partial"