package routes import ( "net/http" "github.com/gin-gonic/gin" "gorm.io/gorm" "wx_service/internal/handler" "wx_service/internal/middleware" ) func Register(router *gin.Engine, db *gorm.DB, authHandler *handler.AuthHandler, videoHandler *handler.VideoHandler) { // Register 用来集中注册所有 HTTP 路由,便于工程结构更清晰: // - main 只负责初始化(配置/DB/依赖注入) // - routes 只负责把 URL 映射到 handler api := router.Group("/api/v1") { // 登录接口:用微信 code 换取/创建用户并返回 session_key(作为后续 Bearer Token) api.POST("/auth/login", authHandler.LoginWithWeChat) // 需要登录的接口组:统一挂载鉴权中间件 protected := api.Group("") protected.Use(middleware.AuthMiddleware(db)) { protected.POST("/video/remove_watermark", videoHandler.RemoveWatermark) protected.POST("/video/remove_watermark/unlock", videoHandler.UnlockQuota) } } // 健康检查:用于容器/负载均衡探活 router.GET("/healthz", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"status": "ok"}) }) }