Select correct lang in request, use timeout for request, fix sighandler panic

This commit is contained in:
eleksir
2026-05-03 16:41:32 +03:00
parent 7d3c083cea
commit 11ea7b8398
5 changed files with 19 additions and 5 deletions

View File

@@ -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.
}