安全修复: - WebSocket Token 增加 Redis 有效性校验(已登出用户无法建立 WS) 功能修复: - GetRecommendFriends 改为批量查询,正确返回用户名/昵称/头像 - 上下线通知:OnlineService 通过接口注入获取好友列表推送状态变更 - 管理端在线用户 API 补充用户名信息 代码质量: - 所有 json.Marshal/Redis 错误增加检查与日志 - ContactController 13 个 endpoint 统一走 handleError 业务错误映射 - 管理端 Controller 补全包注释、函数注释和结构化日志 - 前端 5 个联系人页面 avatar 工具函数抽取到 utils/avatar.js Made-with: Cursor
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package ws
|
|
|
|
import (
|
|
"github.com/echochat/backend/config"
|
|
"github.com/echochat/backend/pkg/ws"
|
|
"github.com/google/wire"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
// ProvideHub 创建并启动 Hub 实例
|
|
// Hub.Run() 在后台 goroutine 运行,服务关闭时通过 hub.Stop() 优雅退出
|
|
func ProvideHub() *ws.Hub {
|
|
hub := ws.NewHub()
|
|
go hub.Run()
|
|
return hub
|
|
}
|
|
|
|
// ProvidePubSub 创建 PubSub 实例
|
|
func ProvidePubSub(rdb *redis.Client, hub *ws.Hub) *ws.PubSub {
|
|
return ws.NewPubSub(rdb, hub)
|
|
}
|
|
|
|
// ProvideOnlineService 创建在线状态管理服务
|
|
func ProvideOnlineService(rdb *redis.Client, hub *ws.Hub, pubsub *ws.PubSub, friendGetter FriendIDsGetter) *OnlineService {
|
|
return NewOnlineService(rdb, hub, pubsub, friendGetter)
|
|
}
|
|
|
|
// ProvideWSHandler 创建 WebSocket Handler
|
|
func ProvideWSHandler(hub *ws.Hub, pubsub *ws.PubSub, cfg *config.JWTConfig, onlineService *OnlineService, tokenValidator TokenValidator) *Handler {
|
|
return NewHandler(hub, pubsub, cfg, onlineService, tokenValidator)
|
|
}
|
|
|
|
// WSSet WebSocket 模块 Wire Provider Set
|
|
var WSSet = wire.NewSet(
|
|
ProvideHub,
|
|
ProvidePubSub,
|
|
ProvideOnlineService,
|
|
ProvideWSHandler,
|
|
)
|