u
This commit is contained in:
26
request.go
26
request.go
@@ -7,23 +7,19 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
var client *resty.Client
|
||||
type SilentLogger struct{}
|
||||
|
||||
func init() {
|
||||
client = resty.New()
|
||||
client.SetRetryCount(3).SetRetryWaitTime(3 * time.Second).AddRetryCondition(
|
||||
func (s SilentLogger) Errorf(string, ...any) {}
|
||||
func (s SilentLogger) Warnf(string, ...any) {}
|
||||
func (s SilentLogger) Debugf(string, ...any) {}
|
||||
|
||||
func NewRestyClient() *resty.Client {
|
||||
return resty.New().SetRetryCount(10).SetRetryWaitTime(3 * time.Second).AddRetryCondition(
|
||||
func(r *resty.Response, err error) bool {
|
||||
return err != nil || r.StatusCode() == http.StatusTooManyRequests
|
||||
if err != nil || r.StatusCode() == http.StatusTooManyRequests {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func request() *resty.Request {
|
||||
return client.R().SetLogger(disableLogger{}).SetHeader("Accept-Charset", "utf-8").SetHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0")
|
||||
}
|
||||
|
||||
type disableLogger struct{}
|
||||
|
||||
func (d disableLogger) Errorf(string, ...interface{}) {}
|
||||
func (d disableLogger) Warnf(string, ...interface{}) {}
|
||||
func (d disableLogger) Debugf(string, ...interface{}) {}
|
||||
|
||||
Reference in New Issue
Block a user