Documentation ¶
Overview ¶
Package sse implements Server-Sent Events, as specified in RFC 6202.
Index ¶
Constants ¶
const (
EOF = "\n"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) OnConnection ¶
func (c *Client) OnConnection(handler func())
OnConnection callback function upon successful connection registration (not guaranteed to be faster than the first response data)
func (*Client) OnDisconnect ¶
OnDisconnect callback function when connection is disconnected
func (*Client) OnExit ¶
func (c *Client) OnExit(handler func())
OnExit callback function when client stop
func (*Client) SubscribeEvent ¶
func (c *Client) SubscribeEvent(eventName string, callback EventCallback)
SubscribeEvent Subscribe to callbacks for events
type EventCallback ¶
type EventCallback func(message *Message)
EventCallback Define the type of SSE event subscription callback function
type Hub ¶
type Hub struct { ConnectedFunc func(clientID string) //连接建立时的处理逻辑 DisconnectFunc func(clientID string) //连接建立时的处理逻辑 // contains filtered or unexported fields }
Hub Global SSE Hub reply is nil, no record push message, otherwise it will record
func (*Hub) RegisterBlock ¶
func (hub *Hub) RegisterBlock(w http.ResponseWriter, r *http.Request, zone string, uuid func() string)
RegisterBlock registers SSE connections Zone string zone names default Uuid func() string is a function that generates a connection ID, using GetClientID() by default
func (*Hub) SendMessage ¶
SendMessage sends messages, whether to broadcast is controlled by the Packet parameter
func (*Hub) StartBroadcast ¶
func (hub *Hub) StartBroadcast()
StartBroadcast messages to all connections
func (*Hub) UnRegisterBlock ¶
UnRegisterBlock Unregister Connection Delete Data in Map
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link server 连接 messageChan 推送消息通道 createTime 连接创建时的时间戳(秒级)
type Log ¶
type Log interface { Info(args ...interface{}) Infoln(args ...interface{}) Infof(format string, args ...interface{}) Debug(args ...interface{}) Debugln(args ...interface{}) Debugf(format string, args ...interface{}) Warn(args ...interface{}) Warnln(args ...interface{}) Warnf(format string, args ...interface{}) Error(args ...interface{}) Errorln(args ...interface{}) Errorf(format string, args ...interface{}) }
Log 常用日志结构体注入接口
type Message ¶
type Message struct { ID string //消息ID,可选 Event string //server 监听事件名称,必填 Data string //发送内容 Retry string //重试 Comment string //注释 // contains filtered or unexported fields }
Message 消息内容
func (*Message) WriteConnect ¶
func (m *Message) WriteConnect(w http.ResponseWriter) error
WriteConnect // Push message to client