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
28 lines
812 B
Go
28 lines
812 B
Go
// Package im 提供即时通讯模块
|
|
package im
|
|
|
|
import (
|
|
"github.com/echochat/backend/app/im/controller"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// RegisterRoutes 注册 IM 模块的所有路由(需要 JWT 中间件)
|
|
func RegisterRoutes(r *gin.Engine, ctrl *controller.IMController, jwtAuth gin.HandlerFunc) {
|
|
authed := r.Group("/api/v1/im")
|
|
authed.Use(jwtAuth)
|
|
{
|
|
// 会话管理
|
|
authed.GET("/conversations", ctrl.GetConversations)
|
|
authed.PUT("/conversations/:id/pin", ctrl.PinConversation)
|
|
authed.DELETE("/conversations/:id", ctrl.DeleteConversation)
|
|
authed.DELETE("/conversations/:id/messages", ctrl.ClearHistory)
|
|
|
|
// 消息
|
|
authed.GET("/messages", ctrl.GetHistoryMessages)
|
|
authed.GET("/messages/search", ctrl.SearchMessages)
|
|
|
|
// 未读数
|
|
authed.GET("/unread", ctrl.GetTotalUnread)
|
|
}
|
|
}
|