49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package httpclient
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"likedream-goframe/internal/application/cookiejar"
|
|
"likedream-goframe/internal/utils"
|
|
"time"
|
|
|
|
"resty.dev/v3"
|
|
)
|
|
|
|
var Xuexitong = resty.New().
|
|
SetCookieJar(cookiejar.NewAllSavePersistCookieJar()).
|
|
SetRedirectPolicy(resty.FlexibleRedirectPolicy(20)).
|
|
SetTimeout(30 * time.Second).
|
|
SetTLSClientConfig(&tls.Config{
|
|
InsecureSkipVerify: true,
|
|
})
|
|
|
|
func init() {
|
|
if !utils.IsDebug() {
|
|
Xuexitong.SetDebug(false)
|
|
} else {
|
|
Xuexitong.SetProxy("http://127.0.0.1:9000")
|
|
}
|
|
}
|
|
|
|
// NewXuexitongClient 创建一个全新的独立 client 实例,避免 Clone 可能的浅拷贝问题
|
|
// 每个实例都是完全独立的,适用于并发场景,不会共享状态
|
|
func NewXuexitongClient() *resty.Client {
|
|
client := resty.New().
|
|
SetCookieJar(nil).
|
|
SetTimeout(30*time.Second).
|
|
SetDoNotParseResponse(false).
|
|
SetTLSClientConfig(&tls.Config{
|
|
InsecureSkipVerify: true,
|
|
}).
|
|
SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
|
|
|
|
// 根据调试模式设置代理和调试选项
|
|
if !utils.IsDebug() {
|
|
client.SetDebug(false)
|
|
} else {
|
|
client.SetProxy("http://127.0.0.1:9000")
|
|
}
|
|
|
|
return client
|
|
}
|