sse_hub

package
v1.2.21 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PushHandler

func PushHandler(c echo.Context) error

PushHandler 服务器端广播接口:POST /api/push { "message": "...", "event": "可选", "id": "可选" }

func SSEHandler

func SSEHandler(c echo.Context) error

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 NewHub

func NewHub() *Hub

NewHub 创建一个新的 Hub 实例

func (*Hub) Add

func (h *Hub) Add(id string, ch chan Event)

Add 注册一个新的客户端

func (*Hub) Broadcast

func (h *Hub) Broadcast(ev Event)

Broadcast 向所有注册的客户端广播事件

func (*Hub) BroadcastMessage

func (h *Hub) BroadcastMessage(msg string)

BroadcastMessage 向所有注册的客户端广播纯文本消息(简化版)

func (*Hub) Clear

func (h *Hub) Clear()

Clear 关闭并清空所有客户端连接

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount 返回当前注册的客户端数量

func (*Hub) ClientIDs

func (h *Hub) ClientIDs() []string

ClientIDs 返回当前注册的所有客户端 ID 列表

func (*Hub) CloseAll

func (h *Hub) CloseAll()

CloseAll 关闭所有客户端连接并清空列表(用于优雅关机)

func (*Hub) Remove

func (h *Hub) Remove(id string)

Remove 注销一个客户端

func (*Hub) SendToClient

func (h *Hub) SendToClient(id string, ev Event)

SendToClient 向某一个客户端发送消息

Jump to

Keyboard shortcuts

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