这是一个基于 Gin 框架实现的接口测试学习和压测学习平台。
POST /api/user/registerPOST /api/user/loginGET /api/user/user_info (需要token)POST /api/user/user_change (需要token)POST /api/user/change_password (需要token)POST /api/user/logout (需要token)GET /api/chameleon/public_param (需要token)POST /api/chameleon/public_param (需要token)GET /api/chameleon/interface_category (需要token)POST /api/chameleon/interface_category (需要token)PUT /api/chameleon/interface_category (需要token)DELETE /api/chameleon/interface_category (需要token)GET /api/chameleon/interface (需要token)POST /api/chameleon/interface (需要token)PUT /api/chameleon/interface (需要token)DELETE /api/chameleon/interface (需要token)POST /api/chameleon/interface_batch_delete (需要token)POST /api/qa_tools/encrypt_decrypt (需要token)POST /api/qa_tools/create_sign (需要token)GET /api/qa_tools/person_info (需要token)GET /api/qa_tools/kabin_infoGET /api/qa_tools/interface_mock (需要token)GET /api/sparrow/studentPOST /api/sparrow/studentPOST /api/sparrow/student_encrypt (需要token)POST /api/sparrow/student_signapi-test-platform/ ├── config/ # 配置和数据库模型 │ └── config.go ├── controllers/ # 控制器 │ ├── user_controller.go │ ├── chameleon_controller.go │ ├── qatools_controller.go │ └── sparrow_controller.go ├── middleware/ # 中间件 │ └── auth.go ├── routes/ # 路由 │ └── router.go ├── utils/ # 工具函数 │ ├── response.go │ ├── jwt.go │ ├── encrypt.go │ └── random.go ├── main.go # 主程序入口 ├── go.mod # Go模块文件 └── README.md # 项目文档
go mod tidy
go build -o api-test-platform main.go
./api-test-platform
服务将在 http://localhost:8080 启动
curl -X POST http://localhost:8080/api/user/register \
-H "Content-Type: application/json" \
-d '{
"phone": "13800138000",
"email": "test@qq.com",
"nick": "测试用户",
"password": "123456",
"password2": "123456"
}'
curl -X POST http://localhost:8080/api/user/login \
-H "Content-Type: application/json" \
-d '{
"username": "13800138000",
"password": "123456"
}'
响应会返回 token,后续请求需要在 Header 中携带 token。
curl -X GET http://localhost:8080/api/user/user_info \
-H "token: <your-token-here>"
curl -X POST http://localhost:8080/api/sparrow/student \
-H "Content-Type: application/json" \
-d '{
"name": "张三",
"grade": "一年级",
"phone": "13900139000",
"age": 18,
"sex": "男"
}'
# 加密
curl -X POST http://localhost:8080/api/qa_tools/encrypt_decrypt \
-H "Content-Type: application/json" \
-H "token: <your-token-here>" \
-d '{
"type": 1,
"data": "hello world"
}'
# 解密
curl -X POST http://localhost:8080/api/qa_tools/encrypt_decrypt \
-H "Content-Type: application/json" \
-H "token: <your-token-here>" \
-d '{
"type": 2,
"data": "<encrypted-data>"
}'
curl -X POST http://localhost:8080/api/qa_tools/create_sign \
-H "Content-Type: application/json" \
-H "token: <your-token-here>" \
-d '{
"name": "张三",
"age": 18
}'
curl -X GET "http://localhost:8080/api/qa_tools/person_info?bank_code=ICBC&card_type=DC" \
-H "token: <your-token-here>"
本项目适合用于接口测试和压测学习,可以使用以下工具进行压测:
ab -n 1000 -c 100 http://localhost:8080/api/sparrow/student
wrk -t12 -c400 -d30s http://localhost:8080/api/sparrow/student
from locust import HttpUser, task, between
class APIUser(HttpUser):
wait_time = between(1, 3)
@task
def get_student_list(self):
self.client.get("/api/sparrow/student")
在 config/config.go 中可以修改以下配置:
type ServerConfig struct {
Port string // 服务端口,默认 8080
RunMode string // 运行模式: debug/release
}
type SecretConfig struct {
JwtSecret string // JWT 密钥
EncryptKey string // AES 加密密钥
SignKey string // 签名密钥
}
type DatabaseConfig struct {
Type string // 数据库类型
Path string // 数据库文件路径
}
MIT License