Documentation ¶
Index ¶
- Constants
- Variables
- func NewFeatureWsConnector(url string, retry int) *wsConnector
- func SetLogger(log v1log.ILog)
- type ActionEvent
- type BroadcastFeature
- type Client
- type ClientsMgr
- type FeatureActionsMgr
- type FeatureSubscribeGroup
- type FeatureSubscribeMgr
- func (sub *FeatureSubscribeMgr) Group(name string) ISubscribeGroup
- func (sub *FeatureSubscribeMgr) Groups() map[string]ISubscribeGroup
- func (sub *FeatureSubscribeMgr) JoinGroup(client *Client, name string)
- func (sub *FeatureSubscribeMgr) Parse(data []byte) (ISubscribeGroup, bool)
- func (sub *FeatureSubscribeMgr) ParseJoinGroup(client *Client, data []byte) (ISubscribeGroup, bool)
- func (sub *FeatureSubscribeMgr) QuitAllGroup(client *Client)
- func (sub *FeatureSubscribeMgr) QuitGroup(client *Client, name string)
- func (sub *FeatureSubscribeMgr) Subscribe(client *Client, data []byte) ISubscribeGroup
- func (sub *FeatureSubscribeMgr) SubscribeAction(client *Client, data []byte)
- func (sub *FeatureSubscribeMgr) UnSubscribe(client *Client, data []byte) ISubscribeGroup
- func (sub *FeatureSubscribeMgr) UnSubscribeAction(client *Client, data []byte)
- type Hub
- type IActionEvent
- type IClientsMgr
- type IOnline
- type ISubscribeGroup
- type IWorkerMgr
- type OnlineWorker
- type WebSocketMessage
- type WsConnector
Constants ¶
View Source
const GroupKey = "group"
View Source
const SubscribeKey = "subscribe"
View Source
const UnSubscribeKey = "unsubscribe"
Variables ¶
View Source
var UnExceptedCloseErr = []int{ websocket.CloseGoingAway, websocket.CloseAbnormalClosure, websocket.CloseInternalServerErr, websocket.CloseMandatoryExtension, websocket.CloseMessageTooBig, websocket.ClosePolicyViolation, websocket.CloseProtocolError, websocket.CloseTLSHandshake, }
UnExceptedCloseErr 不处理的关闭错误
Functions ¶
func NewFeatureWsConnector ¶
NewFeatureWsConnector ws辅助连接器
Types ¶
type ActionEvent ¶
type ActionEvent struct {
// contains filtered or unexported fields
}
func NewActionEvent ¶
func NewActionEvent(name string, f func(client *Client, data []byte)) *ActionEvent
func (*ActionEvent) Do ¶
func (act *ActionEvent) Do(client *Client, data []byte)
func (*ActionEvent) Name ¶
func (act *ActionEvent) Name() string
type BroadcastFeature ¶
type BroadcastFeature struct{}
BroadcastFeature 广播辅助功能
func (BroadcastFeature) Send ¶
func (b BroadcastFeature) Send(clients []*Client, msg interface{})
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a middleman between the websocket connection and the hub.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(message interface{})
type ClientsMgr ¶
type ClientsMgr struct {
// contains filtered or unexported fields
}
ClientsMgr 联机客户端管理
func NewClientsMgr ¶
func NewClientsMgr() *ClientsMgr
func (*ClientsMgr) AddClient ¶
func (w *ClientsMgr) AddClient(c *Client)
func (*ClientsMgr) Clients ¶
func (w *ClientsMgr) Clients() []*Client
func (*ClientsMgr) Conns ¶
func (w *ClientsMgr) Conns() int64
func (*ClientsMgr) DeleteClient ¶
func (w *ClientsMgr) DeleteClient(c *Client)
type FeatureActionsMgr ¶
type FeatureActionsMgr struct {
// contains filtered or unexported fields
}
FeatureActionsMgr ws操作事件管理器
func NewFeatureActionsMgr ¶
func NewFeatureActionsMgr(actions ...IActionEvent) *FeatureActionsMgr
func (*FeatureActionsMgr) GetAction ¶
func (mgr *FeatureActionsMgr) GetAction(name string) (IActionEvent, error)
GetAction 获取对应action
func (*FeatureActionsMgr) Parse ¶
func (mgr *FeatureActionsMgr) Parse(data []byte) (IActionEvent, error)
Parse 解析数据,数据格式满足一下
func (*FeatureActionsMgr) ParseDo ¶
func (mgr *FeatureActionsMgr) ParseDo(client *Client, data []byte) (IActionEvent, error)
ParseDo 解析数据并且执行
type FeatureSubscribeGroup ¶
type FeatureSubscribeGroup struct { IClientsMgr // contains filtered or unexported fields }
FeatureSubscribeGroup ws订阅Group功能
func NewFeatureSubscribeGroup ¶
func NewFeatureSubscribeGroup(name ...string) *FeatureSubscribeGroup
func (*FeatureSubscribeGroup) Name ¶
func (g *FeatureSubscribeGroup) Name() string
func (*FeatureSubscribeGroup) SetName ¶
func (g *FeatureSubscribeGroup) SetName(n string)
type FeatureSubscribeMgr ¶
type FeatureSubscribeMgr struct {
// contains filtered or unexported fields
}
FeatureSubscribeMgr ws订阅功能,负责解析和管理订阅Group
func NewFeatureSubscribeMgr ¶
func NewFeatureSubscribeMgr(groups ...ISubscribeGroup) *FeatureSubscribeMgr
func (*FeatureSubscribeMgr) Group ¶
func (sub *FeatureSubscribeMgr) Group(name string) ISubscribeGroup
Group 指定group
func (*FeatureSubscribeMgr) Groups ¶
func (sub *FeatureSubscribeMgr) Groups() map[string]ISubscribeGroup
Groups 所有groups
func (*FeatureSubscribeMgr) JoinGroup ¶
func (sub *FeatureSubscribeMgr) JoinGroup(client *Client, name string)
JoinGroup 加入指定group
func (*FeatureSubscribeMgr) Parse ¶
func (sub *FeatureSubscribeMgr) Parse(data []byte) (ISubscribeGroup, bool)
Parse 解析订阅数据,返回参数:
group,对应group bool,true:加入订阅,false:退出订阅 如果对应数据格式是group的则返回的bool不准确,由上层自己判断 支持的数据格式1: {"action":"subscribe","group":"Trade"} 上面这个数据格式适用于配合 FeatureActionsMgr 使用 支持的数据格式2: {"subscribe":"Trade"} 支持的数据格式3: {"unsubscribe":"Trade"}
func (*FeatureSubscribeMgr) ParseJoinGroup ¶
func (sub *FeatureSubscribeMgr) ParseJoinGroup(client *Client, data []byte) (ISubscribeGroup, bool)
ParseJoinGroup 解析并自动加入group,返回:
对应group true:订阅加入,false:订阅退出
func (*FeatureSubscribeMgr) QuitAllGroup ¶
func (sub *FeatureSubscribeMgr) QuitAllGroup(client *Client)
QuitAllGroup 退出所有group
func (*FeatureSubscribeMgr) QuitGroup ¶
func (sub *FeatureSubscribeMgr) QuitGroup(client *Client, name string)
QuitGroup 退出指定group
func (*FeatureSubscribeMgr) Subscribe ¶
func (sub *FeatureSubscribeMgr) Subscribe(client *Client, data []byte) ISubscribeGroup
Subscribe 订阅方法,用于只处理订阅数据
func (*FeatureSubscribeMgr) SubscribeAction ¶
func (sub *FeatureSubscribeMgr) SubscribeAction(client *Client, data []byte)
func (*FeatureSubscribeMgr) UnSubscribe ¶
func (sub *FeatureSubscribeMgr) UnSubscribe(client *Client, data []byte) ISubscribeGroup
UnSubscribe 取消订阅方法,用于只处理取消订阅数据
func (*FeatureSubscribeMgr) UnSubscribeAction ¶
func (sub *FeatureSubscribeMgr) UnSubscribeAction(client *Client, data []byte)
type Hub ¶
type Hub struct { IClientsMgr // contains filtered or unexported fields }
func (*Hub) ServeHTTP ¶
func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)
用于ws联机的http方法
func (*Hub) SetWorker ¶
func (h *Hub) SetWorker(worker IWorkerMgr)
type IActionEvent ¶
IActionEvent 定义单个action操作时间
type IClientsMgr ¶
type IOnline ¶
type IOnline interface { AddClient(c *Client) DeleteClient(c *Client) Clients() []*Client //return all clients Conns() int64 //return clients num }
IOnline 联机在线管理(已废弃,请使用 IClientsMgr )
type ISubscribeGroup ¶
type ISubscribeGroup interface { Name() string IClientsMgr }
ISubscribeGroup 订阅频道组功能
type IWorkerMgr ¶
type OnlineWorker ¶
type OnlineWorker struct {
// contains filtered or unexported fields
}
OnlineWorker 联机管理worker
func NewOnlineWorker ¶
func NewOnlineWorker() *OnlineWorker
func (*OnlineWorker) AddClient ¶
func (w *OnlineWorker) AddClient(c *Client)
func (*OnlineWorker) Clients ¶
func (w *OnlineWorker) Clients() []*Client
func (*OnlineWorker) Conns ¶
func (w *OnlineWorker) Conns() int64
func (*OnlineWorker) DeleteClient ¶
func (w *OnlineWorker) DeleteClient(c *Client)
type WebSocketMessage ¶
type WebSocketMessage struct { MessageType int `json:"-"` Message []byte `json:"-"` Client *Client `json:"-"` }
WebSocketMessage ws接收消息
Click to show internal directories.
Click to hide internal directories.