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
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
@ -23,7 +22,13 @@ func fetchInstances() ([]Instance, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
|
||||
|
||||
XNGUserAgent, err := GetUserAgent("Text-Search-XNG")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", XNGUserAgent)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
@ -35,7 +40,7 @@ func fetchInstances() ([]Instance, error) {
|
|||
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -53,20 +58,20 @@ func validateInstance(instance Instance) bool {
|
|||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/search?q=test&categories=general&language=en&safe_search=1&page=1&format=json", instance.URL), nil)
|
||||
if err != nil {
|
||||
log.Printf("Error creating request for URL: %s, Error: %v", instance.URL, err)
|
||||
printWarn("Error creating request for URL: %s, Error: %v", instance.URL, err)
|
||||
return false
|
||||
}
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Printf("Error performing request for URL: %s, Error: %v", instance.URL, err)
|
||||
printWarn("Error performing request for URL: %s, Error: %v", instance.URL, err)
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Printf("Instance validation failed for URL: %s, StatusCode: %d", instance.URL, resp.StatusCode)
|
||||
printWarn("Instance validation failed for URL: %s, StatusCode: %d", instance.URL, resp.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue