Skip to content

Commit dade8b0

Browse files
fix: Address linting issues in web search implementation
- Fix errcheck issues by properly handling error returns in defer statements - Fix staticcheck issue by removing unnecessary fmt.Sprintf usage Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>
1 parent 1ad670e commit dade8b0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

config/websearch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestLoadConfig_WebSearch(t *testing.T) {
4444
if err != nil {
4545
t.Fatalf("Failed to create temp dir: %v", err)
4646
}
47-
defer os.RemoveAll(tempDir)
47+
defer func() { _ = os.RemoveAll(tempDir) }()
4848

4949
configPath := filepath.Join(tempDir, "config.yaml")
5050
configContent := `
@@ -138,7 +138,7 @@ func TestSaveConfig_WebSearch(t *testing.T) {
138138
if err != nil {
139139
t.Fatalf("Failed to create temp dir: %v", err)
140140
}
141-
defer os.RemoveAll(tempDir)
141+
defer func() { _ = os.RemoveAll(tempDir) }()
142142

143143
configPath := filepath.Join(tempDir, "config.yaml")
144144

@@ -189,7 +189,7 @@ func TestLoadConfig_MissingWebSearchSection(t *testing.T) {
189189
if err != nil {
190190
t.Fatalf("Failed to create temp dir: %v", err)
191191
}
192-
defer os.RemoveAll(tempDir)
192+
defer func() { _ = os.RemoveAll(tempDir) }()
193193

194194
configPath := filepath.Join(tempDir, "config.yaml")
195195
configContent := `

internal/services/websearch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *WebSearchService) performGoogleSearch(ctx context.Context, query string
104104
if err != nil {
105105
return nil, fmt.Errorf("search request failed: %w", err)
106106
}
107-
defer resp.Body.Close()
107+
defer func() { _ = resp.Body.Close() }()
108108

109109
if resp.StatusCode != http.StatusOK {
110110
// For non-200 responses, return mock results instead of failing
@@ -132,7 +132,7 @@ func (s *WebSearchService) performDuckDuckGoSearch(ctx context.Context, query st
132132
if err != nil {
133133
return nil, fmt.Errorf("search request failed: %w", err)
134134
}
135-
defer resp.Body.Close()
135+
defer func() { _ = resp.Body.Close() }()
136136

137137
if resp.StatusCode != http.StatusOK {
138138
// For non-200 responses, return mock results instead of failing
@@ -199,7 +199,7 @@ func (s *WebSearchService) parseDuckDuckGoResponse(response map[string]interface
199199
if abstract, ok := response["Abstract"].(string); ok && abstract != "" {
200200
if abstractURL, ok := response["AbstractURL"].(string); ok && abstractURL != "" {
201201
results = append(results, domain.WebSearchResult{
202-
Title: fmt.Sprintf("DuckDuckGo Result"),
202+
Title: "DuckDuckGo Result",
203203
URL: abstractURL,
204204
Snippet: abstract,
205205
})

0 commit comments

Comments
 (0)