ProxyRotator
代理池轮换管理系统,支持代理导入、健康检测、智能轮换和 Telegram Bot 管理。
功能特性
- 代理导入 - 支持文本和文件批量导入,自动解析多种代理格式
- 健康检测 - 并发测试代理可用性,记录延迟和成功率
- 智能轮换 - 基于评分的代理选择,支持租约机制防止并发冲突
- 站点隔离 - 同一站点不会分配到相同代理,避免被封禁
- Telegram Bot - 通过 Telegram 管理代理池
- REST API - 完整的 HTTP API 接口
快速开始
环境要求
- Go 1.22+
- PostgreSQL 14+
安装
# 克隆仓库
git clone <repo-url>
cd proxyrotator
# 安装依赖
make deps
# 初始化数据库
export DATABASE_URL="postgres://postgres:password@localhost:5432/proxyrotator"
make migrate
# 构建
make build
配置
复制 envexmaple 为 .env 并修改配置:
DATABASE_URL=postgres://postgres:password@localhost:5432/proxyrotator
LISTEN_ADDR=0.0.0.0:9987
API_KEY=your-secret-key
RETURN_SECRET=true
MAX_CONCURRENCY=200
MAX_TEST_LIMIT=2000
LEASE_TTL=60s
| 配置项 | 说明 | 默认值 |
|---|---|---|
| DATABASE_URL | PostgreSQL 连接字符串 | - |
| LISTEN_ADDR | 监听地址 | 0.0.0.0:9987 |
| API_KEY | API 认证密钥 | - |
| RETURN_SECRET | 返回代理密码 | true |
| MAX_CONCURRENCY | 测试最大并发数 | 200 |
| MAX_TEST_LIMIT | 单次测试最大数量 | 2000 |
| LEASE_TTL | 代理租约有效期 | 60s |
运行
# 直接运行
make run
# 或使用编译后的二进制
./bin/proxyrotator
# 开发模式(热重载)
make dev
API 接口
所有 API 请求需要在 Header 中携带 X-API-Key。
代理导入
# 文本导入
curl -X POST http://localhost:9987/v1/proxies/import/text \
-H "X-API-Key: your-secret-key" \
-H "Content-Type: application/json" \
-d '{"text": "socks5://user:pass@1.2.3.4:1080\nhttp://5.6.7.8:8080"}'
# 文件导入
curl -X POST http://localhost:9987/v1/proxies/import/file \
-H "X-API-Key: your-secret-key" \
-F "file=@proxies.txt"
获取代理
# 获取下一个可用代理
curl http://localhost:9987/v1/proxies/next \
-H "X-API-Key: your-secret-key"
# 指定分组和站点
curl "http://localhost:9987/v1/proxies/next?group=premium&site=example.com" \
-H "X-API-Key: your-secret-key"
代理测试
# 批量测试代理
curl -X POST http://localhost:9987/v1/proxies/test \
-H "X-API-Key: your-secret-key" \
-H "Content-Type: application/json" \
-d '{"group": "default", "limit": 100}'
使用反馈
# 报告代理使用结果
curl -X POST http://localhost:9987/v1/proxies/report \
-H "X-API-Key: your-secret-key" \
-H "Content-Type: application/json" \
-d '{"lease_id": "xxx", "success": true}'
代理管理
# 列出代理
curl "http://localhost:9987/v1/proxies?group=default&status=alive" \
-H "X-API-Key: your-secret-key"
# 获取统计信息
curl http://localhost:9987/v1/proxies/stats \
-H "X-API-Key: your-secret-key"
# 删除代理
curl -X DELETE http://localhost:9987/v1/proxies/{id} \
-H "X-API-Key: your-secret-key"
项目结构
.
├── server/ # 程序入口
├── internal/
│ ├── api/ # HTTP 路由和处理器
│ ├── config/ # 配置加载
│ ├── importer/ # 代理导入和解析
│ ├── model/ # 数据模型
│ ├── security/ # 安全相关
│ ├── selector/ # 代理选择器
│ ├── store/ # 数据库存储
│ ├── telegram/ # Telegram Bot
│ └── tester/ # 代理测试器
└── migrations/ # 数据库迁移
开发
# 格式化代码
make fmt
# 静态检查
make lint
# 运行测试
make test
License
MIT
Description
Languages
Go
95.9%
PLpgSQL
2.9%
Makefile
1.2%