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:
@@ -13,6 +13,10 @@ import (
|
||||
const ContextCurrentUserKey = "currentUser"
|
||||
|
||||
func AuthMiddleware(db *gorm.DB) gin.HandlerFunc {
|
||||
// AuthMiddleware 是一个 Gin 中间件:
|
||||
// - 从 Authorization: Bearer <token> 里取 token
|
||||
// - 用 token(这里是 session_key)查用户
|
||||
// - 查到后放进 gin.Context,供后面的 handler 使用
|
||||
return func(c *gin.Context) {
|
||||
token := extractToken(c.GetHeader("Authorization"))
|
||||
if token == "" {
|
||||
@@ -36,6 +40,7 @@ func AuthMiddleware(db *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
func extractToken(authHeader string) string {
|
||||
// 常见格式:Authorization: Bearer <token>
|
||||
if authHeader == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user