feat(auth): 添加完整的用户认证API项目

- 实现用户注册、登录、JWT令牌认证功能
- 集成Gin、GORM、Viper、Zap等框架
- 添加密码加密、数据库操作、中间件等完整功能
- 配置多环境支持、日志轮转、CORS处理
- 创建完整的项目结构和配置文件体系
This commit is contained in:
liumangmang
2025-12-30 18:00:42 +08:00
parent 7f4527d501
commit b010f82221
139 changed files with 2772 additions and 103 deletions

View File

@@ -0,0 +1,51 @@
package main
import (
"github.com/gin-gonic/gin"
)
// 方式 2独立函数推荐便于单元测试
func getProduct(c *gin.Context) {
productID := c.Param("id")
c.JSON(200, gin.H{
"id": productID,
"name": "Product",
})
}
// 方式 3结构体方法便于依赖注入
type ProductService struct {
name string
}
type ProductHandler struct {
service *ProductService
}
func (h *ProductHandler) Get(c *gin.Context) {
id := c.Param("id")
// 使用 h.service 调用业务逻辑
c.JSON(200, gin.H{
"id": id,
"service_name": h.service.name,
})
}
func main() {
r := gin.Default()
// 方式 1直接定义
r.GET("/method1", func(c *gin.Context) {
c.JSON(200, gin.H{"method": "inline"})
})
// 方式 2使用独立函数
r.GET("/products/:id", getProduct)
// 方式 3使用结构体方法
service := &ProductService{name: "ProductService"}
handler := &ProductHandler{service: service}
r.GET("/products-struct/:id", handler.Get)
r.Run(":9999")
}