From cfbd761a93e36ab2cf955bb51d756a36c5048ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Tue, 19 May 2026 09:40:57 +0400 Subject: [PATCH] Fix Go style violations: error wrapping, imports, URL construction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- pkg/agent/tools/search/firecrawl.go | 16 ++++++++++------ pkg/agent/tools/search/government_db.go | 24 ++++++++++++++---------- pkg/agent/tools/search/web_search.go | 1 - pkg/probod/tracker_mapping.go | 4 +++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pkg/agent/tools/search/firecrawl.go b/pkg/agent/tools/search/firecrawl.go index 83b9a4a64..91163248e 100644 --- a/pkg/agent/tools/search/firecrawl.go +++ b/pkg/agent/tools/search/firecrawl.go @@ -24,7 +24,6 @@ import ( "net/url" "go.gearno.de/kit/httpclient" - "go.probo.inc/probo/pkg/agent" ) @@ -81,7 +80,12 @@ func FirecrawlSearchTool(endpoint, apiKey string) agent.Tool { ) } -func firecrawlSearch(ctx context.Context, client *http.Client, endpoint, apiKey, query string, maxResults int) ([]searchResult, error) { +func firecrawlSearch( + ctx context.Context, + client *http.Client, + endpoint, apiKey, query string, + maxResults int, +) ([]searchResult, error) { u, err := url.JoinPath(endpoint, "search") if err != nil { return nil, fmt.Errorf("cannot build search URL: %w", err) @@ -97,20 +101,20 @@ func firecrawlSearch(ctx context.Context, client *http.Client, endpoint, apiKey, req, err := http.NewRequestWithContext(ctx, http.MethodPost, u, bytes.NewReader(body)) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot create request: %w", err) } req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+apiKey) resp, err := client.Do(req) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot execute search request: %w", err) } defer func() { _ = resp.Body.Close() }() respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot read response body: %w", err) } if resp.StatusCode != http.StatusOK { @@ -119,7 +123,7 @@ func firecrawlSearch(ctx context.Context, client *http.Client, endpoint, apiKey, var fcResp firecrawlResponse if err := json.Unmarshal(respBody, &fcResp); err != nil { - return nil, err + return nil, fmt.Errorf("cannot unmarshal response: %w", err) } if !fcResp.Success { diff --git a/pkg/agent/tools/search/government_db.go b/pkg/agent/tools/search/government_db.go index 02df23f10..1b9f13e9d 100644 --- a/pkg/agent/tools/search/government_db.go +++ b/pkg/agent/tools/search/government_db.go @@ -23,7 +23,6 @@ import ( "net/url" "go.gearno.de/kit/httpclient" - "go.probo.inc/probo/pkg/agent" ) @@ -114,31 +113,36 @@ func CheckGovernmentDBTool(searchEndpoint string) agent.Tool { } func searxngSearch(ctx context.Context, client *http.Client, endpoint, query string, maxResults int) ([]searchResult, error) { - u, err := url.Parse(endpoint + "/search") + u, err := url.JoinPath(endpoint, "search") if err != nil { - return nil, err + return nil, fmt.Errorf("cannot build search URL: %w", err) } - q := u.Query() + parsed, err := url.Parse(u) + if err != nil { + return nil, fmt.Errorf("cannot parse search URL: %w", err) + } + + q := parsed.Query() q.Set("q", query) q.Set("format", "json") q.Set("categories", "general") - u.RawQuery = q.Encode() + parsed.RawQuery = q.Encode() - req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, parsed.String(), nil) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot create request: %w", err) } resp, err := client.Do(req) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot execute search request: %w", err) } defer func() { _ = resp.Body.Close() }() body, err := io.ReadAll(resp.Body) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot read response body: %w", err) } if resp.StatusCode != http.StatusOK { @@ -147,7 +151,7 @@ func searxngSearch(ctx context.Context, client *http.Client, endpoint, query str var searxResp searxngResponse if err := json.Unmarshal(body, &searxResp); err != nil { - return nil, err + return nil, fmt.Errorf("cannot unmarshal response: %w", err) } results := make([]searchResult, 0, maxResults) diff --git a/pkg/agent/tools/search/web_search.go b/pkg/agent/tools/search/web_search.go index 536d888a4..3c31503f3 100644 --- a/pkg/agent/tools/search/web_search.go +++ b/pkg/agent/tools/search/web_search.go @@ -19,7 +19,6 @@ import ( "net/http" "go.gearno.de/kit/httpclient" - "go.probo.inc/probo/pkg/agent" ) diff --git a/pkg/probod/tracker_mapping.go b/pkg/probod/tracker_mapping.go index 86dc4c3f4..fb66dd16a 100644 --- a/pkg/probod/tracker_mapping.go +++ b/pkg/probod/tracker_mapping.go @@ -15,6 +15,8 @@ package probod import ( + "fmt" + "github.com/prometheus/client_golang/prometheus" "go.gearno.de/kit/log" "go.opentelemetry.io/otel/trace" @@ -41,7 +43,7 @@ func (impl *Implm) buildTrackerMappingConfig( r, ) if err != nil { - return cookiebanner.TrackerMappingConfig{}, err + return cookiebanner.TrackerMappingConfig{}, fmt.Errorf("cannot resolve tracker mapping agent client: %w", err) } return cookiebanner.TrackerMappingConfig{