Enhance API and error handling for video services

- Updated .gitignore to exclude cache files.
- Refactored main.go to streamline route registration and improve code organization.
- Added detailed comments in auth_handler.go, video_handler.go, and service files for better clarity on request handling and service logic.
- Improved error messages in video_handler.go to provide clearer feedback to users in Chinese.
- Introduced context handling in service methods to manage request timeouts effectively.
This commit is contained in:
nepiedg
2025-12-31 02:30:20 +00:00
parent 97cadb033e
commit d23b253609
8 changed files with 98 additions and 27 deletions
+35
View File
@@ -0,0 +1,35 @@
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"})
})
}