Documentation ¶
Index ¶
- type ActionFunc
- type EventMessage
- type Server
- type WebSocketManager
- func (wsm *WebSocketManager) BroadcastMessage(event string, data interface{}) ([]*websocket.Conn, error)
- func (wsm *WebSocketManager) Close(ctx context.Context)
- func (wsm *WebSocketManager) HandleConnection(w http.ResponseWriter, r *http.Request)
- func (wsm *WebSocketManager) RemoveClient(conn *websocket.Conn)
- func (wsm *WebSocketManager) SendEvent(conn *websocket.Conn, event string, data interface{}) error
- func (wsm *WebSocketManager) SendMessageToClient(conn *websocket.Conn, event string, data interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventMessage ¶
type EventMessage struct { Event string `json:"event"` Data interface{} `json:"data"` }
EventMessage 是发送给客户端的事件消息的结构。
type WebSocketManager ¶
type WebSocketManager struct {
// contains filtered or unexported fields
}
WebSocketManager 管理与客户端的WebSocket连接。
func NewWebSocketManager ¶
func NewWebSocketManager(ctx context.Context) *WebSocketManager
NewWebSocketManager 初始化一个新的WebSocketManager并返回其指针。
func (*WebSocketManager) BroadcastMessage ¶
func (wsm *WebSocketManager) BroadcastMessage(event string, data interface{}) ([]*websocket.Conn, error)
BroadcastMessage 将消息广播到所有连接的WebSocket客户端。 如果发送失败,返回发送失败的连接列表和最后一个错误。
func (*WebSocketManager) Close ¶
func (wsm *WebSocketManager) Close(ctx context.Context)
Close 关闭所有的WebSocket连接并清除clients。
func (*WebSocketManager) HandleConnection ¶
func (wsm *WebSocketManager) HandleConnection(w http.ResponseWriter, r *http.Request)
HandleConnection 处理新的WebSocket连接请求。
func (*WebSocketManager) RemoveClient ¶
func (wsm *WebSocketManager) RemoveClient(conn *websocket.Conn)
RemoveClient 从管理器中移除一个WebSocket客户端连接。
func (*WebSocketManager) SendEvent ¶
func (wsm *WebSocketManager) SendEvent(conn *websocket.Conn, event string, data interface{}) error
SendEvent 将事件消息发送到给定的WebSocket连接。
func (*WebSocketManager) SendMessageToClient ¶
func (wsm *WebSocketManager) SendMessageToClient(conn *websocket.Conn, event string, data interface{}) error
SendMessageToClient 将消息发送到特定的WebSocket客户端。
Click to show internal directories.
Click to hide internal directories.