fix(proxy): 修复代理地址换行符问题并优化代理池初始化
- 将代理URL中的换行符由\r\n修改为\n,避免解析错误 - 代理相关配置文件及Dockerfile中统一调整换行符格式 - flyfishv2卡片发送模块设置正确的User-Agent头部 - 使用strutil.SplitAndTrim代替strings.Split优化代理IP列表处理 - 修正全局代理池单例初始化方式,确保线程安全 - 调整main.go中包引入顺序,提升代码规范性
This commit is contained in:
@@ -231,7 +231,7 @@ proxies = []
|
||||
```go
|
||||
func GetProxyInfo() ProxyInfo {
|
||||
return ProxyInfo{
|
||||
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\r\\n&distinct=false"),
|
||||
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\n&distinct=false"),
|
||||
AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"),
|
||||
AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"),
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ ENV TZ=Asia/Shanghai \
|
||||
shopAddr="" \
|
||||
proxy="" \
|
||||
proxyName="qkgo" \
|
||||
proxyUrl="https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\r\n&distinct=false" \
|
||||
proxyUrl="https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\n&distinct=false" \
|
||||
proxyAuthKey="7ASQH2BI" \
|
||||
proxyAuthPwd="34D6652FE7B6"
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ type ProxyInfo struct {
|
||||
|
||||
func GetProxyInfo() ProxyInfo {
|
||||
return ProxyInfo{
|
||||
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\r\\n&distinct=false"),
|
||||
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\n&distinct=false"),
|
||||
AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"),
|
||||
AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"),
|
||||
}
|
||||
|
||||
@@ -32,14 +32,13 @@ type Pool struct {
|
||||
|
||||
var (
|
||||
globalProxyPool *Pool
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// GetGlobalProxyPool 获取全局代理池实例
|
||||
func GetGlobalProxyPool() *Pool {
|
||||
once.Do(func() {
|
||||
sync.OnceFunc(func() {
|
||||
globalProxyPool = NewProxyPool()
|
||||
})
|
||||
})()
|
||||
return globalProxyPool
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/otelTrace"
|
||||
"gateway/internal/utils"
|
||||
"gateway/internal/utils/useragent"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -104,6 +105,7 @@ func (s *SendCardTaskTypeFlyFishV2) HandleSendCardTask(ctx context.Context, orde
|
||||
SetHeader("accept", "application/json, text/javascript, */*; q=0.01").
|
||||
SetHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8").
|
||||
SetHeader("origin", "https://apify.fkpay.online").
|
||||
SetHeader("user-agent", useragent.GetUserAgentByPlatform(useragent.PlatformPhone)).
|
||||
SetHeader("referer", "https://apify.fkpay.online/show.html?orderId=FY17568845864231914279").
|
||||
SetTimeout(time.Second * 20).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
|
||||
proxy, _ := utils.GetProxy(ctx, utils.GenerateId(), "SendCardTaskTypeFlyFishV2_cardTask")
|
||||
|
||||
@@ -442,7 +442,8 @@ func (p *OrderBasedProxyStrategy) tryGetProxy(ctx context.Context) ([]string, er
|
||||
return []string{}, fmt.Errorf("获取代理IP失败")
|
||||
}
|
||||
|
||||
proxyIPs := strings.Split(proxyIP, "\n")
|
||||
proxyIPs := strutil.SplitAndTrim(proxyIP, "\n")
|
||||
|
||||
slice.ForEach(proxyIPs, func(index int, item string) {
|
||||
proxyIPs[index] = strutil.Trim(item)
|
||||
})
|
||||
|
||||
5
main.go
5
main.go
@@ -14,11 +14,10 @@ import (
|
||||
"gateway/internal/service/supplier/third_party"
|
||||
"gateway/internal/service/supplier/third_party/queue"
|
||||
"gateway/internal/utils"
|
||||
"log"
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"log"
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user