Select correct lang in request, use timeout for request, fix sighandler panic
This commit is contained in:
@@ -26,10 +26,12 @@ func APIClient() (string, error) {
|
||||
_, _, day := time.Now().Date()
|
||||
userAgent := Config.UserAgents[day-1]
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := requests.URL(url).UserAgent(userAgent).
|
||||
Header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8").
|
||||
Header("Accept-Language", "en-US,en;q=0.5").
|
||||
Header("User-Agent", "ru-RU").
|
||||
Header("Accept-Language", "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7").
|
||||
Header("Accept-Charset", "utf-8").ToString(&respBody).Fetch(ctx); err != nil {
|
||||
return "", fmt.Errorf("Unable to GET %s: %w", url, err) //nolint: staticcheck // Looks like golangci-lint ignoring settings about fucking ST1005 check. We want readable errors despite what wants author of linter or assholes from go dev team.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user