From 9aaed88cc10422f439cb624607bd05896c968a42 Mon Sep 17 00:00:00 2001 From: hhs <386998068@qq.com> Date: Sun, 14 Jun 2026 17:26:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20main.go=20=E6=8E=A5=E5=85=A5=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E6=9C=8D=E5=8A=A1=EF=BC=88TokenManager=20+=20AuthServ?= =?UTF-8?q?ice=20+=20AuthHandler=20=E8=B7=AF=E7=94=B1=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/cmd/server/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index 8091719..9bc51b0 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -12,6 +12,7 @@ import ( "github.com/gin-gonic/gin" "github.com/hhs/camtalk/internal/api" + "github.com/hhs/camtalk/internal/auth" "github.com/hhs/camtalk/internal/ai/llm" "github.com/hhs/camtalk/internal/ai/stt" "github.com/hhs/camtalk/internal/ai/tts" @@ -60,6 +61,10 @@ func main() { _ = pool } + // 初始化 UserRepository(内存模式用于无 DB 场景) + var userRepo store.UserRepository + userRepo = store.NewMemUserRepository() + // 初始化 Session Manager(MVP 默认内存实现) var sessionMgr session.Manager // TODO: 当 Redis 配置非空时切换为 RedisManager @@ -105,6 +110,14 @@ func main() { // 初始化 Orchestrator orch := orchestrator.New(sttService, llmService, ttsService, sessionMgr, cfg) + // 初始化认证服务 + tokenMgr := auth.NewTokenManager( + cfg.Auth.JWTSecret, + time.Duration(cfg.Auth.AccessTTL)*time.Minute, + time.Duration(cfg.Auth.RefreshTTL)*time.Minute, + ) + authService := auth.NewAuthService(tokenMgr, userRepo) + // Gin 模式 if cfg.App.Env == "prod" { gin.SetMode(gin.ReleaseMode) @@ -123,6 +136,10 @@ func main() { sessionHandler := api.NewSessionHandler(sessionMgr) sessionHandler.RegisterRoutes(apiGroup) + // Auth REST 端点 + authHandler := api.NewAuthHandler(authService, tokenMgr) + authHandler.RegisterRoutes(apiGroup) + // WebSocket r.GET("/ws", ws.ServeWS(sessionMgr, orch, cfg))