replaced deprecated 'io/ioutil' with 'io'
Some checks failed
Run Integration Tests / test (push) Failing after 39s
Some checks failed
Run Integration Tests / test (push) Failing after 39s
This commit is contained in:
parent
851b93bed5
commit
24c7a09479
3 changed files with 26 additions and 11 deletions
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -21,12 +21,14 @@ func PerformBraveTextSearch(query, safe, lang string, offset int) ([]TextSearchR
|
|||
|
||||
req, err := http.NewRequest("GET", searchURL, nil)
|
||||
if err != nil {
|
||||
printWarn("Error creating request: %v", err)
|
||||
return nil, 0, fmt.Errorf("creating request: %v", err)
|
||||
}
|
||||
|
||||
// Set headers including User-Agent
|
||||
TextUserAgent, err := GetUserAgent("Text-Search")
|
||||
if err != nil {
|
||||
printWarn("Error generating User-Agent: %v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
req.Header.Set("User-Agent", TextUserAgent)
|
||||
|
@ -35,19 +37,22 @@ func PerformBraveTextSearch(query, safe, lang string, offset int) ([]TextSearchR
|
|||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
printWarn("Error performing request: %v", err)
|
||||
return nil, 0, fmt.Errorf("performing request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Read the response body
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
printWarn("Error reading response body: %v", err)
|
||||
return nil, 0, fmt.Errorf("reading response body: %v", err)
|
||||
}
|
||||
|
||||
// Parse the response body
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(body)))
|
||||
if err != nil {
|
||||
printErr("Error parsing response body: %v", err)
|
||||
return nil, 0, fmt.Errorf("parsing response body: %v", err)
|
||||
}
|
||||
|
||||
|
@ -71,8 +76,10 @@ func PerformBraveTextSearch(query, safe, lang string, offset int) ([]TextSearchR
|
|||
|
||||
// Return an error if no results are found
|
||||
if len(results) == 0 {
|
||||
printDebug("No results found for query: %s", query)
|
||||
return nil, duration, fmt.Errorf("no results found")
|
||||
}
|
||||
|
||||
printDebug("Search completed successfully for query: %s, found %d results", query, len(results))
|
||||
return results, duration, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue