Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateUuid(node *snowflake.Node) string
- func GetLocalIpToInt() (uint32, error)
- func TraceClientCloseFailedLog(params, data, err interface{}, level logrus.Level)
- func TraceClientCloseSuccessLog(params, data, err interface{}, level logrus.Level)
- func TraceHeartbeatErrdLog(params, data, err interface{}, level logrus.Level)
- func TraceLog(code Code, params, data, err interface{}, level logrus.Level)
- func TraceReadMsgSuccessLog(params, data interface{}, level logrus.Level)
- func TraceSendMsgErrLog(params, data, err interface{}, level logrus.Level)
- func TraceSuccessLog(params, data interface{}, level logrus.Level)
- func WriteBindGroupSuccessJson(conn *websocket.Conn, data, params interface{}) error
- func WriteClientCloseFailedJson(conn *websocket.Conn, data, params interface{}) error
- func WriteClientCloseSuccessJson(conn *websocket.Conn, data, params interface{}) error
- func WriteClientFailedJson(conn *websocket.Conn, data, params interface{}) error
- func WriteClientNotExistJson(conn *websocket.Conn, data, params interface{}) error
- func WriteFailedJson(conn *websocket.Conn, data, params interface{}) error
- func WriteHeartbeatErrJson(conn *websocket.Conn, data, params interface{}) error
- func WriteJson(conn *websocket.Conn, code Code, message string, data, params interface{}) error
- func WriteMessage(conn *websocket.Conn, code Code, message string, data, params interface{}, ...) error
- func WriteReadMsgErrJson(conn *websocket.Conn, data, params interface{}) error
- func WriteReadMsgSuccessJson(conn *websocket.Conn, data, params interface{}) error
- func WriteRequestParamErrJson(conn *websocket.Conn, data, params interface{}) error
- func WriteSendMsgErrJson(conn *websocket.Conn, data, params interface{}) error
- func WriteSendMsgSuccessJson(conn *websocket.Conn, data, params interface{}) error
- func WriteSuccessJson(conn *websocket.Conn, data, params interface{}) error
- type BroadcastChan
- type Client
- type Code
- type Hub
- func (m *Hub) AllBroadcastHandle(msg []byte)
- func (m *Hub) ClientBroadcastHandle(clientId string, msg []byte)
- func (m *Hub) GetGroupClients(name string) ([]*Client, error)
- func (m *Hub) GetSystemClients(name string) ([]*Client, error)
- func (m *Hub) GroupBroadcastHandle(groupId string, msg []byte)
- func (m *Hub) RemoveClientByGroup(client *Client) error
- func (m *Hub) RemoveGroup(name string)
- func (m *Hub) RemoveSystem(name string)
- func (m *Hub) Run()
- func (m *Hub) SetClientToGroups(groupId string, client *Client) bool
- func (m *Hub) SystemBroadcastHandle(systemId string, msg []byte)
- type MsgType
Constants ¶
const ( Text MsgType = 1 Json = iota + Text Binary )
Variables ¶
var CodeMap = map[Code]string{ Success: "客户端连接成功", Failed: "客户端连接失败", ClientFailed: "客户端主动断连", ClientNotExist: "客户端不存在", ClientCloseSuccess: "客户端关闭成功", ClientCloseFailed: "客户端关闭失败", ReadMsgErr: "读取消息体失败", ReadMsgSuccess: "读取消息体成功", SendMsgErr: "发送消息体失败", SendMsgSuccess: "发送消息体成功", HeartbeatErr: "心跳检测失败", SystemErr: "系统不能为空", BindGroupSuccess: "绑定群组成功", BindGroupErr: "绑定群组失败", UnAuthed: "用户未认证", InternalErr: "服务器内部错误", RequestMethodErr: "请求方式错误", RequestParamErr: "请求参数错误", }
var (
Logger *logrus.Logger
)
var (
Node *snowflake.Node
)
Functions ¶
func TraceClientCloseFailedLog ¶
TraceClientCloseFailedLog 客户端关闭失败消息
func TraceClientCloseSuccessLog ¶
TraceClientCloseSuccessLog 客户端关闭成功消息
func TraceHeartbeatErrdLog ¶
TraceHeartbeatErrdLog 心跳检测失败消息
func TraceReadMsgSuccessLog ¶
TraceReadMsgSuccessLog 读取消息体成功消息
func TraceSendMsgErrLog ¶
TraceSendMsgErrLog 发送消息体失败
func TraceSuccessLog ¶
TraceSuccessLog 客户端连接成功消息
func WriteBindGroupSuccessJson ¶
WriteBindGroupSuccessJson 返回绑定群组成功
func WriteClientCloseFailedJson ¶
WriteClientCloseFailedJson 返回客户端关闭失败
func WriteClientCloseSuccessJson ¶
WriteClientCloseSuccessJson 返回客户端关闭成功
func WriteClientFailedJson ¶
WriteClientFailedJson 返回客户端主动断连
func WriteClientNotExistJson ¶
WriteClientNotExistJson 返回客户端不存在
func WriteFailedJson ¶
WriteFailedJson 返回客户端连接失败
func WriteHeartbeatErrJson ¶
WriteHeartbeatErrJson 返回心跳检测失败
func WriteMessage ¶
func WriteMessage(conn *websocket.Conn, code Code, message string, data, params interface{}, msgType MsgType) error
WriteMessage 返回给客户端的信息
func WriteReadMsgErrJson ¶
WriteReadMsgErrJson 返回读取消息体失败
func WriteReadMsgSuccessJson ¶
WriteReadMsgSuccessJson 返回读取消息体成功
func WriteRequestParamErrJson ¶
WriteRequestParamErrJson 返回请求参数错误
func WriteSendMsgErrJson ¶
WriteSendMsgErrJson 返回发送消息体失败
func WriteSendMsgSuccessJson ¶
WriteSendMsgSuccessJson 返回发送消息体成功
func WriteSuccessJson ¶
WriteSuccessJson 返回客户端连接成功
Types ¶
type BroadcastChan ¶
type Client ¶
type Client struct { ClientId string `json:"client_id"` // 客户端连接ID GroupId string `json:"group_id"` // 群组id SystemId string `json:"system_id"` // 系统ID 为分布式做准备的 Conn *websocket.Conn // contains filtered or unexported fields }
func (*Client) ReadMessageHandler ¶
func (c *Client) ReadMessageHandler()
ReadMessageHandler 将来自 websocket 连接的消息推送到集线器。
func (*Client) WriteMessageHandler ¶
WriteMessageHandler 将消息从集线器发送到 websocket 连接
type Hub ¶
type Hub struct { Clients map[*Client]bool // 全部客户端列表 {*Client1: bool, *Client2: bool...} SystemClients map[string][]*Client // 全部系统列表 {"systemId1": []*Clients{*Client1, *Client2...}, "systemId2": []*Clients{*Client1, *Client2...}} GroupClients map[string][]*Client // 全部群组列表 {"groupId": []*Clients{*Client1, *Client2...}} ClientRegister chan *Client // 客户端连接处理 ClientUnregister chan *Client // 客户端断开连接处理 ClientLock sync.RWMutex // 客户端列表读写锁 Broadcast chan []byte // 来自广播的入站消息 SystemBroadcast chan *BroadcastChan // 来自群组的入站消息 {Name:"systemId", Msg:"msg"} GroupBroadcast chan *BroadcastChan // 来自群组的入站消息 {Name:"groupId", Msg:"msg"} ClientBroadcast chan *BroadcastChan // 来自客户端的入站消息 {Name:"clientId", Msg:"msg"} }
func (*Hub) AllBroadcastHandle ¶
AllBroadcastHandle 全局广播
func (*Hub) ClientBroadcastHandle ¶
ClientBroadcastHandle 单客户端通道处理
func (*Hub) GetGroupClients ¶
GetGroupClients 获取群组的客户端列表
func (*Hub) GetSystemClients ¶
GetSystemClients 获取系统的客户端列表
func (*Hub) GroupBroadcastHandle ¶
GroupBroadcastHandle 群组消息通道处理
func (*Hub) RemoveClientByGroup ¶
RemoveClientByGroup 从群组删除客户端
func (*Hub) SetClientToGroups ¶
SetClientToGroups 添加客户端到分组
func (*Hub) SystemBroadcastHandle ¶
SystemBroadcastHandle 系统广播处理