Documentation
¶
Index ¶
- func PushHandler(c echo.Context) error
- func SSEHandler(c echo.Context) error
- type Event
- type Hub
- func (h *Hub) Add(id string, ch chan Event)
- func (h *Hub) Broadcast(ev Event)
- func (h *Hub) BroadcastMessage(msg string)
- func (h *Hub) Clear()
- func (h *Hub) ClientCount() int
- func (h *Hub) ClientIDs() []string
- func (h *Hub) CloseAll()
- func (h *Hub) Remove(id string)
- func (h *Hub) SendToClient(id string, ev Event)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PushHandler ¶
PushHandler 服务器端广播接口:POST /api/push { "message": "...", "event": "可选", "id": "可选" }
func SSEHandler ¶
Types ¶
type Event ¶
type Event struct {
Name string // 可选:自定义事件名(不写则走默认 "message" 事件)
ID string // 可选:事件 ID(配合 Last-Event-ID 可断点续传)
Data string // 必填:消息内容
}
Event SSE消息
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub 广播中心
var MessageHub *Hub
func (*Hub) BroadcastMessage ¶
BroadcastMessage 向所有注册的客户端广播纯文本消息(简化版)
Click to show internal directories.
Click to hide internal directories.