This commit is contained in:
2025-12-03 19:32:01 +08:00
parent 87a5bfa2c8
commit 9b08975480

View File

@@ -809,7 +809,33 @@ build_from_source() {
# 取第一个镜像进行测试
first_proxy=$(echo "$proxy_list" | cut -d',' -f1)
echo -n " 测试代理链: ${first_proxy}... "
if curl -sf --connect-timeout 3 --max-time 5 "${first_proxy}" > /dev/null 2>&1; then
# 使用 Go 代理的特定端点进行测试(访问一个已知的模块信息)
# goproxy.cn 等代理服务需要访问 /{module}/@v/list 这样的端点
# 这里测试访问 goproxy.cn 的根路径或使用 go env 测试
TEST_URL="${first_proxy}"
# 尝试多种测试方法
PROXY_AVAILABLE=false
# 方法1: 直接访问根路径
if curl -sf --connect-timeout 3 --max-time 5 "${TEST_URL}" > /dev/null 2>&1; then
PROXY_AVAILABLE=true
# 方法2: 访问 goproxy.cn 的统计页面(如果存在)
elif curl -sf --connect-timeout 3 --max-time 5 "${TEST_URL}/statistics" > /dev/null 2>&1; then
PROXY_AVAILABLE=true
# 方法3: 使用 go env 测试(如果 Go 已安装)
elif command -v go > /dev/null 2>&1; then
# 临时设置 GOPROXY 并测试
if GOPROXY="${first_proxy},direct" go env GOPROXY > /dev/null 2>&1; then
PROXY_AVAILABLE=true
fi
# 方法4: 尝试访问一个已知模块的列表端点
elif curl -sf --connect-timeout 3 --max-time 5 "${TEST_URL}/github.com/gin-gonic/gin/@v/list" > /dev/null 2>&1; then
PROXY_AVAILABLE=true
fi
if [ "$PROXY_AVAILABLE" = true ]; then
GO_PROXY="$proxy_list"
echo -e "${GREEN}可用${NC}"
break