24 lines
532 B
Go
24 lines
532 B
Go
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/go-resty/resty/v2"
|
|
)
|
|
|
|
var client *resty.Client
|
|
|
|
func init() {
|
|
client = resty.New()
|
|
client.SetRetryCount(3).SetRetryWaitTime(3 * time.Second).AddRetryCondition(
|
|
func(r *resty.Response, err error) bool {
|
|
return err != nil || r.StatusCode() == http.StatusTooManyRequests
|
|
},
|
|
)
|
|
}
|
|
|
|
func Request() *resty.Request {
|
|
return client.R().SetHeader("Accept-Charset", "utf-8").SetHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0")
|
|
}
|