sse

package
v0.0.0-...-790eabe Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MulanPSL-2.0 Imports: 2 Imported by: 0

README

sse

基于github.com/r3labs/ssev2版本,封装的sse服务端和客户端库。

使用方法(服务端):

SSE.Instance.AutoStream = true
SSE.Instance.AutoReplay = false

// gin使用
g.GET("sse", gin.WrapF(SSE.Instance.ServeHTTP))

目前客户端连接服务端尚未测通。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Instance *sse.Client // 连接
	Url      string      // 服务端地址
}

客户端

func NewClient

func NewClient(url string) *Client

新建客户端

func (*Client) Subscribe

func (c *Client) Subscribe(stream string, f func(data []byte)) error

订阅信息流

type Server

type Server struct {
	Instance *sse.Server // 服务端实例
}

服务端

func NewServer

func NewServer() *Server

新建服务端

func (*Server) Publish

func (s *Server) Publish(stream string, data []byte)

往一个信息流里发消息

func (*Server) PublishJson

func (s *Server) PublishJson(stream string, data interface{})

往一个信息流里发消息(JSON序列化)

func (*Server) Register

func (s *Server) Register(stream string) *sse.Stream

注册一个信息流

func (*Server) Remove

func (s *Server) Remove(stream string)

移除一个信息流

Jump to

Keyboard shortcuts

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