Documentation ¶
Index ¶
- type Client
- func (c *Client) AddHandlers(handlers ...Handler)
- func (c *Client) AppID() string
- func (c *Client) Cancel() context.CancelFunc
- func (c *Client) Conn() *websocket.Conn
- func (c *Client) ConnID() string
- func (c *Client) ConnTime() time.Time
- func (c *Client) Ctx() context.Context
- func (c *Client) IsAlive() bool
- func (c *Client) SendJSON(v any) error
- func (c *Client) SendMsg(msgData []byte, msgType ...int)
- func (c *Client) SetHandlers(handlers ...Handler)
- func (c *Client) UserID() string
- type Handler
- type Manager
- func (m *Manager) BroadcastMsg(msgData []byte, msgType ...int)
- func (m *Manager) DelClient(connID string)
- func (m *Manager) GetClient(connID string) (*Client, bool)
- func (m *Manager) GetClients() []*Client
- func (m *Manager) GetUserClient(userID, appID string) (*Client, bool)
- func (m *Manager) GetUserClients(userID string) ([]*Client, bool)
- func (m *Manager) SendMsgToClient(connID string, msgData []byte, msgType ...int)
- func (m *Manager) SendMsgToUser(userID string, msgData []byte, msgType ...int)
- func (m *Manager) UpgradeClient(w http.ResponseWriter, r *http.Request, opts ...Option) (*Client, error)
- type Msg
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct { Upgrader *websocket.Upgrader // websocket 协议升级器 ReadTimeout time.Duration // 读取超时时间,要大于 HeartbeatInterval WriteTimeout time.Duration // 写入超时时间 HeartbeatInterval time.Duration // 心跳间隔时间 MaxMessageSize int64 // 最大消息字节大小 // contains filtered or unexported fields }
Manager websocket 管理器
func (*Manager) BroadcastMsg ¶
BroadcastMsg 广播消息
func (*Manager) GetUserClient ¶
GetUserClient 获取用户 websocket 客户端
func (*Manager) GetUserClients ¶
GetUserClients 获取用户 websocket 客户端列表
func (*Manager) SendMsgToClient ¶
SendMsgToClient 发送消息至指定客户端
func (*Manager) SendMsgToUser ¶
SendMsgToUser 发送消息至指定用户
func (*Manager) UpgradeClient ¶
func (m *Manager) UpgradeClient(w http.ResponseWriter, r *http.Request, opts ...Option) (*Client, error)
UpgradeClient 将 http 连接升级为 websocket 客户端
Click to show internal directories.
Click to hide internal directories.