sse

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamSimple

func StreamSimple(ctx *gin.Context, producer Producer, logger *zap.Logger) error

StreamSimple 简化的SSE流式推送函数(向后兼容)

Types

type Config

type Config struct {
	BufferSize int    `json:"buffer_size"` // 消息通道缓冲区大小,默认为1
	EventName  string `json:"event_name"`  // SSE事件名称,默认为"message"
}

Config SSE配置

type Handler

type Handler interface {
	// Stream 启动SSE流式推送
	Stream(ctx *gin.Context, producer Producer, config ...*Config) error
	// StreamWithContext 使用自定义上下文启动SSE流式推送
	StreamWithContext(ctx context.Context, writer io.Writer, producer Producer, config ...*Config) error
}

Handler SSE处理器接口

func NewHandler

func NewHandler(logger *zap.Logger) Handler

NewHandler 创建新的SSE处理器

type Producer

type Producer func(ctx context.Context, msgChan chan<- interface{})

Producer 生产者函数类型,用于产生SSE数据

Jump to

Keyboard shortcuts

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