sse

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleUsage

func ExampleUsage()

使用示例函数

func SSEHandler

func SSEHandler(stream *Stream) gin.HandlerFunc

SSEHandler 创建SSE处理器的便捷函数

Types

type Client

type Client struct {
	ID     string
	Sender *SSenderImpl
	Events chan *sse.Event
}

Client 客户端信息

type SSESender

type SSESender interface {
	Send(ctx context.Context, event *sse.Event) error
	Close() error
}

SSESender SSE发送器接口

type SSenderImpl

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

SSenderImpl Gin SSE发送器实现

func NewSSESender

func NewSSESender(c *gin.Context) *SSenderImpl

NewSSESender 创建新的SSE发送器

func (*SSenderImpl) Close

func (s *SSenderImpl) Close() error

Close 关闭SSE连接

func (*SSenderImpl) IsClosed

func (s *SSenderImpl) IsClosed() bool

IsClosed 检查连接是否已关闭

func (*SSenderImpl) Send

func (s *SSenderImpl) Send(ctx context.Context, event *sse.Event) error

Send 发送SSE事件

func (*SSenderImpl) SendJSON

func (s *SSenderImpl) SendJSON(ctx context.Context, eventType string, data interface{}) error

SendJSON 发送JSON数据的便捷方法

func (*SSenderImpl) SendString

func (s *SSenderImpl) SendString(ctx context.Context, eventType, data string) error

SendString 发送字符串数据的便捷方法

func (*SSenderImpl) SendWithID

func (s *SSenderImpl) SendWithID(ctx context.Context, id, eventType string, data interface{}) error

SendWithID 发送带ID的事件

type Stream

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

Stream SSE流管理器

func NewStream

func NewStream() *Stream

NewStream 创建新的SSE流

func (*Stream) AddClient

func (s *Stream) AddClient(client *Client)

AddClient 添加客户端

func (*Stream) Publish

func (s *Stream) Publish(event *sse.Event)

Publish 广播消息到所有客户端

func (*Stream) RemoveClient

func (s *Stream) RemoveClient(client *Client)

RemoveClient 移除客户端

func (*Stream) Start

func (s *Stream) Start()

Start 启动流管理器

func (*Stream) Stop

func (s *Stream) Stop()

Stop 停止流管理器

Jump to

Keyboard shortcuts

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