diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-07-04 17:24:02 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-07-04 17:24:02 -0700 |
| commit | ee6629ad78ac62fa14371ea5ddb7474c1fe9c979 (patch) | |
| tree | 186d23424e73797976f6d2f71d193bcbc71dbf76 /internal | |
| parent | 262f66351484369fa65c2e23df81ef682ea06d89 (diff) | |
Fix file handle close warnings by ignoring return values
Updated all file close operations to use anonymous functions that ignore
return values to satisfy golangci-lint errcheck warnings.
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/mobius/account_manager.go | 4 | ||||
| -rw-r--r-- | internal/mobius/api.go | 12 | ||||
| -rw-r--r-- | internal/mobius/ban.go | 2 | ||||
| -rw-r--r-- | internal/mobius/ban_test.go | 2 | ||||
| -rw-r--r-- | internal/mobius/threaded_news.go | 2 | ||||
| -rw-r--r-- | internal/mobius/threaded_news_test.go | 4 |
6 files changed, 13 insertions, 13 deletions
diff --git a/internal/mobius/account_manager.go b/internal/mobius/account_manager.go index 8859c58..d9169c9 100644 --- a/internal/mobius/account_manager.go +++ b/internal/mobius/account_manager.go @@ -18,7 +18,7 @@ func loadFromYAMLFile(path string, data interface{}) error { if err != nil { return err } - defer fh.Close() + defer func() { _ = fh.Close() }() decoder := yaml.NewDecoder(fh) return decoder.Decode(data) @@ -90,7 +90,7 @@ func (am *YAMLAccountManager) Create(account hotline.Account) error { if err != nil { return fmt.Errorf("create account file: %w", err) } - defer file.Close() + defer func() { _ = file.Close() }() b, err := yaml.Marshal(account) if err != nil { diff --git a/internal/mobius/api.go b/internal/mobius/api.go index 0a20d01..f912f60 100644 --- a/internal/mobius/api.go +++ b/internal/mobius/api.go @@ -125,7 +125,7 @@ func (srv *APIServer) OnlineHandler(w http.ResponseWriter, r *http.Request) { } } - json.NewEncoder(w).Encode(users) + _ = json.NewEncoder(w).Encode(users) } type BanRequest struct { @@ -169,7 +169,7 @@ func (srv *APIServer) BanHandler(w http.ResponseWriter, r *http.Request) { } } - w.Write([]byte(`{"msg":"banned"}`)) + _, _ = w.Write([]byte(`{"msg":"banned"}`)) } func (srv *APIServer) UnbanHandler(w http.ResponseWriter, r *http.Request) { @@ -198,7 +198,7 @@ func (srv *APIServer) UnbanHandler(w http.ResponseWriter, r *http.Request) { // TODO: Fallback } - w.Write([]byte(`{"msg":"unbanned"}`)) + _, _ = w.Write([]byte(`{"msg":"unbanned"}`)) } func (srv *APIServer) ListBannedIPsHandler(w http.ResponseWriter, r *http.Request) { @@ -208,7 +208,7 @@ func (srv *APIServer) ListBannedIPsHandler(w http.ResponseWriter, r *http.Reques http.Error(w, "failed to fetch banned IPs", http.StatusInternalServerError) return } - json.NewEncoder(w).Encode(ips) + _ = json.NewEncoder(w).Encode(ips) } else { // TODO: Fallback } @@ -221,7 +221,7 @@ func (srv *APIServer) ListBannedUsernamesHandler(w http.ResponseWriter, r *http. http.Error(w, "failed to fetch banned usernames", http.StatusInternalServerError) return } - json.NewEncoder(w).Encode(users) + _ = json.NewEncoder(w).Encode(users) } else { // TODO: Fallback } @@ -234,7 +234,7 @@ func (srv *APIServer) ListBannedNicknamesHandler(w http.ResponseWriter, r *http. http.Error(w, "failed to fetch banned nicknames", http.StatusInternalServerError) return } - json.NewEncoder(w).Encode(nicks) + _ = json.NewEncoder(w).Encode(nicks) } else { // TODO: Fallback } diff --git a/internal/mobius/ban.go b/internal/mobius/ban.go index 781052b..b4fde95 100644 --- a/internal/mobius/ban.go +++ b/internal/mobius/ban.go @@ -43,7 +43,7 @@ func (bf *BanFile) Load() error { if err != nil { return fmt.Errorf("open file: %v", err) } - defer fh.Close() + defer func() { _ = fh.Close() }() err = yaml.NewDecoder(fh).Decode(&bf.banList) if err != nil { diff --git a/internal/mobius/ban_test.go b/internal/mobius/ban_test.go index 1bf68a4..9f1f5d8 100644 --- a/internal/mobius/ban_test.go +++ b/internal/mobius/ban_test.go @@ -52,7 +52,7 @@ func TestAdd(t *testing.T) { if err != nil { t.Fatalf("Failed to create temp directory: %v", err) } - defer os.RemoveAll(tmpDir) // Clean up the temporary directory. + defer func() { _ = os.RemoveAll(tmpDir) }() // Clean up the temporary directory. // Path to the temporary ban file. tmpFilePath := path.Join(tmpDir, "banfile.yaml") diff --git a/internal/mobius/threaded_news.go b/internal/mobius/threaded_news.go index 67e8282..c7daea4 100644 --- a/internal/mobius/threaded_news.go +++ b/internal/mobius/threaded_news.go @@ -218,7 +218,7 @@ func (n *ThreadedNewsYAML) Load() error { if err != nil { return err } - defer fh.Close() + defer func() { _ = fh.Close() }() n.ThreadedNews = hotline.ThreadedNews{} diff --git a/internal/mobius/threaded_news_test.go b/internal/mobius/threaded_news_test.go index 7f5cdaa..2ff8a84 100644 --- a/internal/mobius/threaded_news_test.go +++ b/internal/mobius/threaded_news_test.go @@ -52,7 +52,7 @@ func TestLoadFromYAMLFile(t *testing.T) { if tt.content != "" { err := os.WriteFile(tt.fileName, []byte(tt.content), 0644) assert.NoError(t, err) - defer os.Remove(tt.fileName) // Cleanup the file after the test + defer func() { _ = os.Remove(tt.fileName) }() // Cleanup the file after the test } var data TestData @@ -161,7 +161,7 @@ func TestThreadedNewsYAML_CreateGrouping(t *testing.T) { if err != nil { t.Fatalf("Failed to create temp directory: %v", err) } - defer os.RemoveAll(tmpDir) // Clean up the temporary directory. + defer func() { _ = os.RemoveAll(tmpDir) }() // Clean up the temporary directory. // Path to the temporary ban file. tmpFilePath := path.Join(tmpDir, "ThreadedNews.yaml") |