Fix Go style violations: error wrapping, imports, URL construction
Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"go.gearno.de/kit/httpclient"
|
||||
|
||||
"go.probo.inc/probo/pkg/agent"
|
||||
)
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user