Files
wx_service/internal/routes/routes.go
T
nepiedg 16844d4a42 Enhance AI and Redis integration for smoke logging features
- Added AI configuration options to .env.example and config.go for OpenAI integration.
- Implemented Redis caching for session management in main.go and auth middleware.
- Updated smoke logging service to support real smoking time (`smoke_at`) and AI advice retrieval.
- Enhanced API routes to include endpoints for AI advice and unlock functionality for non-members.
- Improved database schema with new tables for AI advice and unlock records.
- Expanded documentation to cover new AI features and Redis caching implementation.
2026-01-03 02:14:21 +00:00

57 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package routes
import (
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
authhandler "wx_service/internal/common/auth/handler"
qiniuhandler "wx_service/internal/common/qiniu/handler"
rediscache "wx_service/internal/common/redis/cache"
oahandler "wx_service/internal/common/wechat_official/handler"
membershiphandler "wx_service/internal/membership/handler"
"wx_service/internal/middleware"
rmhandler "wx_service/internal/remove_watermark/handler"
smokehandler "wx_service/internal/smoke/handler"
)
func Register(
router *gin.Engine,
db *gorm.DB,
authHandler *authhandler.AuthHandler,
videoHandler *rmhandler.VideoHandler,
smokeHandler *smokehandler.SmokeHandler,
redeemCodeHandler *membershiphandler.RedeemCodeHandler,
uploadHandler *qiniuhandler.UploadHandler,
oaOAuthHandler *oahandler.OAuthHandler,
sessionCache *rediscache.SessionUserCache,
) {
// Register 用来集中注册所有 HTTP 路由,便于工程结构更清晰:
// - main 只负责初始化(配置/DB/依赖注入)
// - routes 只负责把 URL 映射到 handler
api := router.Group("/api/v1")
{
// 登录接口:用微信 code 换取/创建用户并返回 session_key(作为后续 Bearer Token
api.POST("/auth/login", authHandler.LoginWithWeChat)
// 公众号网页授权:不需要登录(code 本身来自微信授权回调)
registerWeChatOfficialRoutes(api, oaOAuthHandler)
// 需要登录的接口组:统一挂载鉴权中间件
protected := api.Group("")
protected.Use(middleware.AuthMiddleware(db, sessionCache))
{
registerCommonRoutes(protected, uploadHandler)
registerRemoveWatermarkRoutes(protected, videoHandler)
registerMembershipRoutes(protected, redeemCodeHandler)
registerSmokeRoutes(protected, smokeHandler)
}
}
// 健康检查:用于容器/负载均衡探活
router.GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
}