sse

command
v0.9.2 Latest Latest
Warning

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

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

README

sse —— SSE 服务端推送

演示 pkg/transport/sse 的单连接定时推送与多连接广播,适合单向实时通知(比 WebSocket 更轻)。

运行

go run ./examples/sse
# 每秒收到 tick 事件
curl -N http://localhost:8080/time

# 每 2 秒收到 news 事件
curl -N http://localhost:8080/news

说明

  • /timesse.Handler 在连接存活期间按 ticker 推送 Event{Event, Data}
  • /newssse.Broadcaststream.Broadcaster[sse.Event] fan-out 给所有 /news 客户端。
  • 客户端断开时 r.Context().Done() 结束 handler,无需手动清理。

Documentation

Overview

SSE 示例:一个定时推送端点 + 一个广播端点。

Jump to

Keyboard shortcuts

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