Documentation ¶
Index ¶
- Variables
- func NewDataPack() gwiface.Packet
- func NewServer(opt ...Option) gwiface.Server
- func SetConfig(c *gwiface.Config)
- type BaseRouter
- type ConnManager
- func (connMgr *ConnManager) Add(conn gwiface.Connection)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) ClearOneConn(connID int64)
- func (connMgr *ConnManager) Get(connID int64) (gwiface.Connection, error)
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Remove(conn gwiface.Connection)
- func (connMgr *ConnManager) Search(s gwiface.Search)
- type Connection
- func (c *Connection) Context() context.Context
- func (c *Connection) GetConnID() int64
- func (c *Connection) GetConnection() *websocket.Conn
- func (c *Connection) GetPing() bool
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) IsHeartbeatTimeout()
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) RemovePing()
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendMsg(msgID uint32, data []byte) error
- func (c *Connection) SetPing()
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) StartReader()
- func (c *Connection) StartWriter()
- func (c *Connection) Stop()
- type DataPack
- type Message
- type MsgHandle
- func (mh MsgHandle) AddRouter(msgID uint32, router gwiface.Router)
- func (mh MsgHandle) DoMsgHandler(request gwiface.Request)
- func (mh MsgHandle) SendMsgToTaskQueue(request gwiface.Request)
- func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan gwiface.Request)
- func (mh MsgHandle) StartWorkerPool()
- type Option
- type Request
- type Server
- func (s *Server) AddRouter(msgID uint32, router gwiface.Router)
- func (s *Server) CallOnConnStart(conn gwiface.Connection)
- func (s *Server) CallOnConnStop(conn gwiface.Connection)
- func (s *Server) GetConnMgr() gwiface.ConnManager
- func (s *Server) Packet() gwiface.Packet
- func (s *Server) Serve(c *gin.Context)
- func (s *Server) SetOnConnStart(hookFunc func(gwiface.Connection))
- func (s *Server) SetOnConnStop(hookFunc func(gwiface.Connection))
- func (s *Server) Start(c *gin.Context)
- func (s *Server) Stop()
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func NewDataPack ¶
Types ¶
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func NewConnManager ¶
func NewConnManager() *ConnManager
func (*ConnManager) Add ¶
func (connMgr *ConnManager) Add(conn gwiface.Connection)
func (*ConnManager) ClearConn ¶
func (connMgr *ConnManager) ClearConn()
func (*ConnManager) ClearOneConn ¶
func (connMgr *ConnManager) ClearOneConn(connID int64)
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID int64) (gwiface.Connection, error)
func (*ConnManager) Len ¶
func (connMgr *ConnManager) Len() int
func (*ConnManager) Remove ¶
func (connMgr *ConnManager) Remove(conn gwiface.Connection)
func (*ConnManager) Search ¶
func (connMgr *ConnManager) Search(s gwiface.Search)
type Connection ¶
type Connection struct { Server gwiface.Server //這個連線屬於哪一個Server Conn *websocket.Conn //本連線的websocket底層結構 ConnID int64 //ConnectionID可以當成SessionID,應該要唯一的 MsgHandler gwiface.MsgHandle //管理Msg的處理 Heartbeat bool //用來給Timer檢查是否有心跳 OfflineHeartBeatCount int //已經累積幾次沒有心跳,超過n次要把他斷線 sync.RWMutex //讓Connection本身也是一個RWMutex // contains filtered or unexported fields }
Connection
func NewConnection ¶
func NewConnection(s gwiface.Server, conn *websocket.Conn, connID int64, msgHandler gwiface.MsgHandle) *Connection
NewConnection 建立一個新的Connection,有新用戶連上時都會新建
func (*Connection) Context ¶
func (c *Connection) Context() context.Context
Context 回傳ctx,用在自己定義的go routine要把Connection變更狀態
func (*Connection) GetConnection ¶
func (c *Connection) GetConnection() *websocket.Conn
GetConnection 得到內部的socket Conn
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
func (*Connection) IsHeartbeatTimeout ¶
func (c *Connection) IsHeartbeatTimeout()
IsHeartbeatTimeout 自己會陷入無限循環,直到GetPing = false 會中斷連線
func (*Connection) RemoveProperty ¶
func (c *Connection) RemoveProperty(key string)
func (*Connection) SendMsg ¶
func (c *Connection) SendMsg(msgID uint32, data []byte) error
SendMsg 送Message給Client
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
func (*Connection) StartReader ¶
func (c *Connection) StartReader()
StartReader 用來讀Message,取得Message後送給Worker處理
func (*Connection) StartWriter ¶
func (c *Connection) StartWriter()
StartWriter 寫Message出去用的goroutine,主要是送msg給Client
type Message ¶
Message 消息 跟前端實際溝通的內容,msgId用來當type,data是任意struct封裝後的資料
func NewMsgPackage ¶
NewMsgPackage 建立一個Message物件
type MsgHandle ¶
type MsgHandle struct { Apis map[uint32]gwiface.Router // 每個MsgID對應的處理方法 WorkerPoolSize uint32 TaskQueue []chan gwiface.Request // Worker負責取任務的Queue }
MsgHandle -
func NewMsgHandle ¶
func NewMsgHandle() *MsgHandle
func (MsgHandle) DoMsgHandler ¶
func (MsgHandle) SendMsgToTaskQueue ¶
func (*MsgHandle) StartOneWorker ¶
func (MsgHandle) StartWorkerPool ¶
func (mh MsgHandle) StartWorkerPool()
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 請求
func (*Request) GetConnection ¶
func (r *Request) GetConnection() gwiface.Connection
GetConnection 取得connection
type Server ¶
type Server struct { ConnMgr gwiface.ConnManager OnConnStart func(conn gwiface.Connection) OnConnStop func(conn gwiface.Connection) // contains filtered or unexported fields }
Server interface的實現,定義一個Server的類型
func (*Server) CallOnConnStart ¶
func (s *Server) CallOnConnStart(conn gwiface.Connection)
func (*Server) CallOnConnStop ¶
func (s *Server) CallOnConnStop(conn gwiface.Connection)
func (*Server) GetConnMgr ¶
func (s *Server) GetConnMgr() gwiface.ConnManager
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookFunc func(gwiface.Connection))
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookFunc func(gwiface.Connection))
Click to show internal directories.
Click to hide internal directories.