feat(ws): 在线状态管理(Redis SET + TTL 心跳续期)

- app/ws/online_service.go: 上线/下线/心跳续期/批量查询在线状态
- 集成到 WebSocket handler: 连接时写入 Redis, 断线时清除
- client.go: 添加 DisconnectHandler 回调
- Redis 键: echo:user:online (SET) + echo:user:status:{uid} (TTL 60s)

Made-with: Cursor
This commit is contained in:
bujinyuan
2026-03-02 17:10:13 +08:00
parent 632e3b9a28
commit 1c87a466a1
6 changed files with 233 additions and 32 deletions

View File

@@ -19,14 +19,20 @@ 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) *OnlineService {
return NewOnlineService(rdb, hub, pubsub)
}
// ProvideWSHandler 创建 WebSocket Handler
func ProvideWSHandler(hub *ws.Hub, pubsub *ws.PubSub, cfg *config.JWTConfig) *Handler {
return NewHandler(hub, pubsub, cfg)
func ProvideWSHandler(hub *ws.Hub, pubsub *ws.PubSub, cfg *config.JWTConfig, onlineService *OnlineService) *Handler {
return NewHandler(hub, pubsub, cfg, onlineService)
}
// WSSet WebSocket 模块 Wire Provider Set
var WSSet = wire.NewSet(
ProvideHub,
ProvidePubSub,
ProvideOnlineService,
ProvideWSHandler,
)