sse

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SSE

func SSE() gin.HandlerFunc

SSE 中间件,设置必要的响应头

func StreamChunks

func StreamChunks(c *gin.Context, ch <-chan string) error

StreamChunks 流式发送文本块(带增量标记)

func StreamText

func StreamText(c *gin.Context, ch <-chan string) error

StreamText 流式发送文本(适用于 AI 对话场景)

func StreamWithID

func StreamWithID(c *gin.Context, messageID string, ch <-chan string) error

StreamWithID 流式发送带消息 ID 的数据

Types

type SSEWriter

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

SSEWriter SSE 写入器

func NewSSEWriter

func NewSSEWriter(c *gin.Context) (*SSEWriter, error)

NewSSEWriter 创建 SSE 写入器

func (*SSEWriter) KeepAlive

func (w *SSEWriter) KeepAlive() error

KeepAlive 发送保持连接的心跳

func (*SSEWriter) Stream

func (w *SSEWriter) Stream(event string, ch <-chan any) error

Stream 流式发送数据

func (*SSEWriter) WriteDone

func (w *SSEWriter) WriteDone() error

WriteDone 写入完成事件

func (*SSEWriter) WriteError

func (w *SSEWriter) WriteError(err error) error

WriteError 写入错误事件

func (*SSEWriter) WriteEvent

func (w *SSEWriter) WriteEvent(event, data string) error

WriteEvent 写入 SSE 事件 格式: event: <event>\ndata: <data>\n\n

func (*SSEWriter) WriteJSON

func (w *SSEWriter) WriteJSON(event string, data any) error

WriteJSON 写入 JSON 数据

func (*SSEWriter) WriteMessage

func (w *SSEWriter) WriteMessage(data string) error

WriteMessage 写入消息(无事件类型) 格式: data: <data>\n\n

Jump to

Keyboard shortcuts

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