This commit is contained in:
2025-10-28 22:07:44 +11:00
parent 4b6f488f59
commit b99d06a2de
78 changed files with 315 additions and 283 deletions

View File

@@ -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{}) {}