IMController (REST API):
- GET /api/v1/im/conversations: 会话列表
- GET /api/v1/im/messages: 历史消息(游标分页)
- PUT /api/v1/im/conversations/:id/pin: 置顶/取消
- DELETE /api/v1/im/conversations/🆔 删除会话
- DELETE /api/v1/im/conversations/:id/messages: 清空记录
- GET /api/v1/im/messages/search: 全局搜索
- GET /api/v1/im/unread: 全局未读数
Wire 集成:
- IMSet Provider Set + wire.Bind 接口注入
- App struct 新增 IM 字段
- wire_gen.go 手动更新
- OfflinePusher 通过 SetOfflinePusher 注入 WS Handler
Made-with: Cursor
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
// 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/contact"
|
||
imApp "github.com/echochat/backend/app/im"
|
||
"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, app.OnlineController, app.ContactManageController, jwtAuth)
|
||
wsApp.RegisterRoutes(engine, app.WSHandler)
|
||
contact.RegisterRoutes(engine, app.ContactController, jwtAuth)
|
||
imApp.RegisterRoutes(engine, app.IMController, jwtAuth)
|
||
|
||
// [未来] meeting.RegisterRoutes(engine, app.MeetingController, jwtAuth)
|
||
// [未来] notify.RegisterRoutes(engine, app.NotifyController, jwtAuth)
|
||
}
|