Files
EchoChat/backend/go-service/router/router.go
bujinyuan bfb4fb0ccb feat(ws): WebSocket 核心模块(Hub + Client + PubSub + Handler)
- pkg/ws/message.go: 统一消息协议(Message/Response/PushMessage)
- pkg/ws/hub.go: Hub 连接管理(注册/注销/按 userID 查找/在线计数)
- pkg/ws/client.go: 客户端连接封装(readPump/writePump/心跳 30s)
- pkg/ws/pubsub.go: Redis Pub/Sub 消息路由(按用户频道发布/订阅)
- app/ws/handler.go: WebSocket 升级处理(JWT 认证 + 消息分发)
- app/ws/router.go: GET /ws 路由注册
- app/ws/provider.go: Wire Provider Set
- 更新 provider/router 集成 WebSocket 模块

Made-with: Cursor
2026-03-02 16:46:17 +08:00

42 lines
1.4 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 router 主路由汇总入口
// 不含任何具体路由定义,仅调用各模块的 RegisterRoutes 函数
// 新增模块时在 Setup 函数中添加一行调用即可
package router
import (
"time"
"github.com/echochat/backend/app/admin"
"github.com/echochat/backend/app/auth"
"github.com/echochat/backend/app/provider"
wsApp "github.com/echochat/backend/app/ws"
"github.com/echochat/backend/pkg/middleware"
"github.com/echochat/backend/pkg/utils"
"github.com/gin-gonic/gin"
)
// Setup 注册所有路由
// 包含健康检查和各业务模块的路由注册
func Setup(engine *gin.Engine, app *provider.App) {
// 健康检查(不经过业务中间件)
engine.GET("/health", func(c *gin.Context) {
utils.ResponseOK(c, gin.H{
"status": "ok",
"service": "echochat",
"time": time.Now().Format("2006-01-02 15:04:05"),
})
})
// JWT 认证中间件实例(有状态 JWT通过 AuthService 校验 Redis
jwtAuth := middleware.JWTAuth(&app.Config.JWT, app.AuthService)
// --- 各模块路由注册 ---
auth.RegisterRoutes(engine, app.AuthController, app.AdminAuthController, jwtAuth)
admin.RegisterRoutes(engine, app.UserManageController, jwtAuth)
wsApp.RegisterRoutes(engine, app.WSHandler)
// [未来] im.RegisterRoutes(engine, app.ImController, jwtAuth)
// [未来] meeting.RegisterRoutes(engine, app.MeetingController, jwtAuth)
// [未来] notify.RegisterRoutes(engine, app.NotifyController, jwtAuth)
}