Documentation
¶
Index ¶
- Constants
- func ToJson(v interface{}) string
- func UUID(length ...int) string
- type ConnectionContext
- type ConnectionMutex
- func (x *ConnectionMutex) GetGroupClientIds(groupName string) []string
- func (x *ConnectionMutex) GetUidClientId(uid string) []string
- func (x *ConnectionMutex) JoinGroup(clientId, groupName string)
- func (x *ConnectionMutex) LeaveGroup(clientId, groupName string)
- func (x *ConnectionMutex) ListGroup() []string
- func (x *ConnectionMutex) ListGroupClientIds(groupName string) []string
- func (x *ConnectionMutex) LoadConn(clientId string) *websocket.Conn
- func (x *ConnectionMutex) LoadConnContext(clientId string) *ConnectionContext
- func (x *ConnectionMutex) Remove(clientId string)
- func (x *ConnectionMutex) SetUid(clientId, uid string)
- func (x *ConnectionMutex) Store(clientId string, ws *websocket.Conn)
- type Event
- type EventHandler
- type EventProtocol
- type EventProtocolConnect
- type H
- type WebsocketManager
- func (x *WebsocketManager) Handler(w http.ResponseWriter, r *http.Request, responseHeader http.Header)
- func (x *WebsocketManager) Log(format string, v ...interface{})
- func (x *WebsocketManager) LogForce(format string, v ...interface{})
- func (x *WebsocketManager) On(eventName string, f EventHandler) bool
- func (x *WebsocketManager) Send(clientId string, messageType int, data []byte) bool
- func (x *WebsocketManager) ToBytes(v interface{}) []byte
Constants ¶
View Source
const ( EventHelp = iota EventConnect = iota EventClose = iota EventPing = iota EventBindUid = iota EventSendToClient = iota EventSendToUid = iota EventSendToGroup = iota EventBroadcast = iota EventJoinGroup = iota EventLeaveGroup = iota EventListGroup = iota EventListGroupClient = iota )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnectionContext ¶
type ConnectionMutex ¶
type ConnectionMutex struct { Conn map[string]*ConnectionContext // [ClientId => CONNECTION_DATA] Uid map[string]map[string]bool // [Uid => [ClientId => bool]] Group map[string]map[string]bool // [GroupName => [ClientId => bool]] // contains filtered or unexported fields }
func (*ConnectionMutex) GetGroupClientIds ¶
func (x *ConnectionMutex) GetGroupClientIds(groupName string) []string
func (*ConnectionMutex) GetUidClientId ¶
func (x *ConnectionMutex) GetUidClientId(uid string) []string
func (*ConnectionMutex) JoinGroup ¶
func (x *ConnectionMutex) JoinGroup(clientId, groupName string)
func (*ConnectionMutex) LeaveGroup ¶
func (x *ConnectionMutex) LeaveGroup(clientId, groupName string)
func (*ConnectionMutex) ListGroup ¶
func (x *ConnectionMutex) ListGroup() []string
func (*ConnectionMutex) ListGroupClientIds ¶
func (x *ConnectionMutex) ListGroupClientIds(groupName string) []string
func (*ConnectionMutex) LoadConn ¶
func (x *ConnectionMutex) LoadConn(clientId string) *websocket.Conn
func (*ConnectionMutex) LoadConnContext ¶
func (x *ConnectionMutex) LoadConnContext(clientId string) *ConnectionContext
func (*ConnectionMutex) Remove ¶
func (x *ConnectionMutex) Remove(clientId string)
func (*ConnectionMutex) SetUid ¶
func (x *ConnectionMutex) SetUid(clientId, uid string)
type EventHandler ¶
type EventHandler func(clientId string, ws *websocket.Conn, messageType int, data EventProtocol) bool
EventHandler 事件响应格式
type EventProtocol ¶
type EventProtocol struct { ClientId string `json:"client_id"` Event string `json:"event"` Data interface{} `json:"data"` }
EventProtocol ws数据交互格式,基于json,event字段必选
type EventProtocolConnect ¶
type WebsocketManager ¶
type WebsocketManager struct { Conn *ConnectionMutex Config struct { Debug bool } // contains filtered or unexported fields }
func NewWebsocketManager ¶
func NewWebsocketManager(debug ...bool) *WebsocketManager
func (*WebsocketManager) Handler ¶
func (x *WebsocketManager) Handler(w http.ResponseWriter, r *http.Request, responseHeader http.Header)
Handler 开始处理websocket请求
func (*WebsocketManager) Log ¶
func (x *WebsocketManager) Log(format string, v ...interface{})
func (*WebsocketManager) LogForce ¶
func (x *WebsocketManager) LogForce(format string, v ...interface{})
func (*WebsocketManager) On ¶
func (x *WebsocketManager) On(eventName string, f EventHandler) bool
On 注册事件
func (*WebsocketManager) Send ¶
func (x *WebsocketManager) Send(clientId string, messageType int, data []byte) bool
Send 对外接口,用于发送ws消息到指定clientId
func (*WebsocketManager) ToBytes ¶
func (x *WebsocketManager) ToBytes(v interface{}) []byte
Click to show internal directories.
Click to hide internal directories.