live-pk

command
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

live-pk 组合 demo:多房间直播 PK 后端,展示多个原语如何协作。

组合的原语:

  • pkg/versus —— 每个 PK 房间:双方倒计时对抗计分、到点定胜负、事件流
  • pkg/idempotency —— 送礼幂等:同一 giftID 重复请求只计一次(防网络重试重复扣礼物)
  • pkg/counter —— 送礼配额:每用户每分钟送礼次数上限(防刷)
  • pkg/tally —— 高频人气聚合:点赞海量 +1 内存合并、批量落地
  • pkg/keyedmutex —— 按房间的细粒度锁:同房间 start/结算 串行,不同房间并行
  • pkg/eventbus —— 全局 PK 生命周期事件(开始/结束),供榜单/通知模块订阅
  • pkg/idgen —— 生成 PK 房间 ID

运行:go run ./examples/live-pk 然后:

curl localhost:8310/start                                  # 开一局 PK,返回 room
curl -N "localhost:8310/watch?room=<room>"                 # SSE 订阅该房间实时比分
curl "localhost:8310/gift?room=<room>&user=u1&side=A&val=100&gift=g1"
curl "localhost:8310/like?room=<room>"                     # 点赞(高频聚合)
curl "localhost:8310/snapshot?room=<room>"                 # 当前比分快照
curl localhost:8310/rooms                                  # 所有进行中的房间

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL