sse_utils

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SSEConnection

type SSEConnection struct {
	// contains filtered or unexported fields
}

SSEConnection 表示单个SSE连接

func NewConnection

func NewConnection(w http.ResponseWriter) (*SSEConnection, error)

NewConnection 创建新的SSE连接

func (*SSEConnection) Close

func (c *SSEConnection) Close()

Close 关闭连接

func (*SSEConnection) SendMessage

func (c *SSEConnection) SendMessage(msg *SSEMessage) error

SendMessage 发送SSE消息

func (*SSEConnection) StartHeartbeat

func (c *SSEConnection) StartHeartbeat(interval time.Duration)

StartHeartbeat 启动心跳机制

func (*SSEConnection) StopHeartbeat

func (c *SSEConnection) StopHeartbeat()

StopHeartbeat 停止心跳

type SSEMessage

type SSEMessage struct {
	Event   string // 事件类型(可选)
	Data    []byte // 消息内容(必填),支持多行文本
	ID      string // 消息ID(可选)
	Comment string // 注释(可选),以冒号开头
	Retry   int    // 客户端重连时间(单位:毫秒,可选)
}

SSEMessage 表示符合SSE标准的消息

func (*SSEMessage) Encode

func (sm *SSEMessage) Encode() []byte

Encode 将消息编码为SSE格式的字节流

Jump to

Keyboard shortcuts

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