# GameDevHub **Repository Path**: only-win-wisdom/game-dev-hub ## Basic Information - **Project Name**: GameDevHub - **Description**: 专注于游戏开发与互动娱乐的开源项目,提供丰富的工具和资源,支持开发者创造多平台游戏体验。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-10 - **Last Updated**: 2025-10-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 后端 - Gin 框架 一个基于 Go + Gin 框架的微信小程序后端项目,提供完整的用户认证、数据管理等功能。 ## ✨ 特性 - 🚀 **Gin 框架** - 高性能的 Go Web 框架 - 🔐 **JWT 认证** - 安全的用户认证机制 - 📱 **微信小程序登录** - 完整的微信小程序登录流程 - 💾 **GORM** - 强大的 ORM 框架 - 📊 **Redis** - 缓存和 Session 管理 - 📝 **Zap 日志** - 高性能日志系统 - 🛠️ **完善的项目结构** - 清晰的分层架构 ## 📦 项目结构 ``` app/ ├── api/ # API 路由处理器 │ ├── auth_handler.go # 认证相关接口 │ └── user_handler.go # 用户相关接口 ├── config/ # 配置管理 │ └── config.go ├── database/ # 数据库连接 │ ├── database.go # MySQL 连接 │ └── redis.go # Redis 连接 ├── middleware/ # 中间件 │ ├── cors.go # 跨域处理 │ ├── jwt.go # JWT 认证 │ └── logger.go # 日志中间件 ├── models/ # 数据模型 │ ├── user.go # 用户模型 │ └── response.go # 响应模型 ├── router/ # 路由配置 │ └── router.go ├── services/ # 业务逻辑层 │ ├── user_service.go # 用户服务 │ └── wechat_service.go # 微信服务 ├── utils/ # 工具函数 │ ├── jwt.go # JWT 工具 │ └── logger.go # 日志工具 ├── main.go # 程序入口 ├── config.yaml # 配置文件 ├── go.mod # Go 模块管理 └── README_API.md # API 文档 ``` ## 🚀 快速开始 ### 环境要求 - Go 1.21+ - MySQL 5.7+ / 8.0+ - Redis 5.0+ ### 1. 克隆项目 ```bash git clone cd toplay/app ``` ### 2. 安装依赖 ```bash go mod tidy ``` ### 3. 配置数据库 创建 MySQL 数据库: ```sql CREATE DATABASE miniapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ``` ### 4. 修改配置文件 编辑 `config.yaml`: ```yaml server: port: 8080 mode: debug database: host: localhost port: 3306 username: root password: your_password # 修改为你的密码 dbname: miniapp redis: host: localhost port: 6379 jwt: secret: your-secret-key-change-in-production # 生产环境请修改 wechat: app_id: your_wechat_appid # 微信小程序 AppID app_secret: your_wechat_appsecret # 微信小程序 AppSecret ``` ### 5. 运行项目 ```bash go run main.go ``` 服务将在 `http://localhost:8080` 启动 ## 📚 API 文档 详细的 API 文档请查看 [API 文档](app/README_API.md) ### 主要接口 - `POST /api/v1/auth/wechat-login` - 微信小程序登录 - `GET /api/v1/user/info` - 获取用户信息(需要认证) - `PUT /api/v1/user/info` - 更新用户信息(需要认证) - `GET /health` - 健康检查 ## 🔧 开发指南 ### 添加新的 API 1. 在 `models/` 中定义数据模型 2. 在 `services/` 中实现业务逻辑 3. 在 `api/` 中创建处理器 4. 在 `router/router.go` 中注册路由 ### 数据库迁移 程序启动时会自动迁移数据库表。如需手动迁移: ```go database.AutoMigrate(&models.YourModel{}) ``` ## 📖 部署文档 详细的部署文档请查看 [部署文档](app/README_DEPLOY.md) ### Docker 快速部署 ```bash docker-compose up -d ``` ## 🔒 安全建议 1. ✅ 生产环境务必修改 JWT secret 2. ✅ 使用 HTTPS(小程序要求) 3. ✅ 定期更新依赖 4. ✅ 配置防火墙规则 5. ✅ 使用环境变量管理敏感配置 ## 📝 技术栈 - **Web 框架**: [Gin](https://github.com/gin-gonic/gin) - **ORM**: [GORM](https://gorm.io/) - **配置管理**: [Viper](https://github.com/spf13/viper) - **日志**: [Zap](https://github.com/uber-go/zap) - **JWT**: [golang-jwt](https://github.com/golang-jwt/jwt) - **微信 SDK**: [silenceper/wechat](https://github.com/silenceper/wechat) - **Redis**: [go-redis](https://github.com/go-redis/redis) ## 📄 许可证 MIT License ## 🤝 贡献 欢迎提交 Issue 和 Pull Request!📞 联系方式 hui039219@gmail.com 131210wsh@ 如有问题,请提交 Issue。