- 实例配置独立:支持为每个实例单独配置 http/https/socks5 代理,避免单机多开挤兑触发斗鱼出口 IP 限流 - 动态 API 提取:原生支持星空代理等平台的 API 提取(兼容 JSON/文本格式),提供前端一键提取填入与连通性/延迟测速 - 定时前自动拉取:针对 3 分钟短效代理,支持在开抢前 15 秒自动提取并绑定最新 IP,并在预热前完成热连接与时间复校 - 修复复校竞态:将 resyncBeforeTrigger 从 3s 提升至 8s,确保三轮采样在开抢前顺利落盘,消除时钟漂移 - 验证方式:通过 go test ./... 全量测试与前端 vue-tsc/vite 编译,实测通过星空代理 API 解析测试用例
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package app
|
|
|
|
import (
|
|
"douyu_go/internal/client"
|
|
"douyu_go/internal/logger"
|
|
"douyu_go/internal/types"
|
|
)
|
|
|
|
// TestProxy 测试指定代理的连通性、出口公网 IP 与往返延迟。
|
|
func (a *App) TestProxy(proxyURL string) types.ProxyTestResult {
|
|
res := client.TestProxyConnection(proxyURL)
|
|
if res.Success {
|
|
logger.LogEvent("代理", "success", "代理测试成功: IP=%s 归属=%s 延迟=%dms", res.IP, res.Region, res.Latency)
|
|
} else {
|
|
logger.LogEvent("代理", "warn", "代理测试失败: %s", res.Error)
|
|
}
|
|
return res
|
|
}
|
|
|
|
// FetchProxy 从指定 API 提取一个代理 IP。
|
|
func (a *App) FetchProxy(apiURL string) types.ProxyFetchResult {
|
|
res, err := client.FetchProxyFromAPI(apiURL)
|
|
if err != nil {
|
|
logger.LogEvent("代理", "warn", "代理提取失败: %v", err)
|
|
return types.ProxyFetchResult{
|
|
Success: false,
|
|
Error: err.Error(),
|
|
}
|
|
}
|
|
logger.LogEvent("代理", "success", "代理提取成功: %s (IP=%s 端口=%s 地区=%s)", res.ProxyURL, res.IP, res.Port, res.Region)
|
|
return *res
|
|
}
|