--- title: 快速开始 | 5分钟搭建MengStack项目环境 - MengStack官方文档 --- # 快速开始 ## 环境要求 - Go 1.23+ - PostgreSQL 14+ - Redis 7+ - Docker & Docker Compose(可选) ## 使用 Docker Compose 启动(推荐) 最简单的方式是使用 Docker Compose 一键启动所有服务: ```bash # 克隆项目 git clone https://gitea.softunis.com/mengstack/mengstack.git cd mengstack # 启动所有服务 docker-compose up -d # 查看日志 docker-compose logs -f app ``` 服务启动后: - API 服务:`http://localhost:2222` - Swagger UI:`http://localhost:2222/swagger/index.html` - 健康检查:`http://localhost:2222/health` ## 本地开发 ### 1. 安装依赖 ```bash # 下载 Go 模块 go mod download # 确保 PostgreSQL 和 Redis 已启动 ``` ### 2. 配置环境变量 复制 `.env.example` 为 `.env` 并修改: ```bash cp .env.example .env ``` 关键配置项: ```env MENGSTACK_SERVER_PORT=2222 # PostgreSQL MENGSTACK_DB_HOST=localhost MENGSTACK_DB_PORT=5432 MENGSTACK_DB_NAME=mengstack MENGSTACK_DB_USER=postgres MENGSTACK_DB_PASSWORD=your_password # Redis MENGSTACK_REDIS_HOST=localhost MENGSTACK_REDIS_PORT=6379 # JWT MENGSTACK_JWT_SECRET=your_jwt_secret_key ``` ### 3. 启动服务 ```bash # 直接运行 go run cmd/server/main.go # 或使用 Makefile make run ``` ### 4. 验证 ```bash # 健康检查 curl http://localhost:2222/health # 注册新用户 curl -X POST http://localhost:2222/api/v1/auth/register \ -H "Content-Type: application/json" \ -d '{ "email": "admin@example.com", "username": "admin", "password": "password123" }' ``` ## 项目命令 | 命令 | 说明 | |------|------| | `make run` | 启动开发服务 | | `make build` | 编译二进制文件 | | `make test` | 运行测试 | | `make swagger` | 重新生成 API 文档 | | `make lint` | 代码检查 | | `make docker-up` | Docker 启动所有服务 | | `make docker-down` | Docker 停止所有服务 |