Documentation ¶
Index ¶
- Variables
- func Pack(message Message) (packageData []byte, err error)
- type BaseRouter
- type Connection
- type ConnectionManager
- type Homey
- func (h *Homey) AddRouter(msgID uint32, router Router)
- func (h *Homey) CallOnConnClose(conn Connection)
- func (h *Homey) CallOnConnOpen(conn Connection) (err error)
- func (h *Homey) CallOnInit(ctx context.Context)
- func (h *Homey) ConnectionManager() ConnectionManager
- func (h *Homey) Context() context.Context
- func (h *Homey) Distribute()
- func (h *Homey) Echo() echo.HandlerFunc
- func (h *Homey) GetMsgType() int
- func (h *Homey) MessageHandler() MessageHandler
- func (h *Homey) RedirectMsgHandler()
- func (h *Homey) SetOnConnClose(hookFunc func(Connection))
- func (h *Homey) SetOnConnOpen(hookFunc func(Connection) error)
- func (h *Homey) SetOnInit(hookFunc func(context.Context))
- func (h *Homey) Stop()
- func (h *Homey) SubscribeWorldChannel()
- type Message
- type MessageHandler
- type Request
- type Router
- type Server
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Time allowed to write a message to the peer. WriteWait = 10 * time.Second // Time allowed to read the next pong message from the peer. PongWait = 60 * time.Second // Send pings to peer with this period. Must be less than pongWait. PingPeriod = (PongWait * 9) / 10 // Maximum message size allowed from peer. MaxMessageSize int64 = 64 * 1024 )
Functions ¶
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
func (*BaseRouter) Handle ¶
func (br *BaseRouter) Handle(request Request) (err error)
func (*BaseRouter) PostHandle ¶
func (br *BaseRouter) PostHandle(request Request) (err error)
func (*BaseRouter) PreHandle ¶
func (br *BaseRouter) PreHandle(request Request) (err error)
type Connection ¶
type Connection interface { // get connecton ID GetID() uint64 // establish a connection between server and client Open() // close a connection Close() // reading message from websocket connection StartReader() // prepare for writing message into websocket connection StartWriter() // server send message to client by connection SendMsg(data []byte) error Context() context.Context }
func NewEchoConnection ¶
func NewEchoConnection(id uint64, server Server, conn *websocket.Conn) Connection
type ConnectionManager ¶
type ConnectionManager interface { // add a connection into connection manager Add(Connection) // remove a connection from connection manager Remove(Connection) // get a connection by connection ID Get(uint64) (Connection, error) // count how many connections in total Count() int // disconnect all connections Clear() }
func NewConnectionManager ¶
func NewConnectionManager() ConnectionManager
type Homey ¶
type Homey struct { ConnManager ConnectionManager MsgHandler MessageHandler RedirectMsgChan chan *[]byte OnInit func(context.Context) OnConnOpen func(Connection) error OnConnClose func(Connection) // contains filtered or unexported fields }
func (*Homey) CallOnConnClose ¶
func (h *Homey) CallOnConnClose(conn Connection)
func (*Homey) CallOnConnOpen ¶
func (h *Homey) CallOnConnOpen(conn Connection) (err error)
func (*Homey) CallOnInit ¶
func (*Homey) ConnectionManager ¶
func (h *Homey) ConnectionManager() ConnectionManager
func (*Homey) Distribute ¶
func (h *Homey) Distribute()
func (*Homey) GetMsgType ¶
func (*Homey) MessageHandler ¶
func (h *Homey) MessageHandler() MessageHandler
func (*Homey) RedirectMsgHandler ¶
func (h *Homey) RedirectMsgHandler()
func (*Homey) SetOnConnClose ¶
func (h *Homey) SetOnConnClose(hookFunc func(Connection))
func (*Homey) SetOnConnOpen ¶
func (h *Homey) SetOnConnOpen(hookFunc func(Connection) error)
func (*Homey) SubscribeWorldChannel ¶
func (h *Homey) SubscribeWorldChannel()
type Message ¶
type Message interface { // get send message connection id GetConnID() uint64 // get package type GetDataType() uint32 // get message data GetData() []byte // get message data length GetDataLength() uint32 // set eventually send message connection id SetConnID(connID uint64) // set package type SetDataType(messageType uint32) // set message data SetData(data []byte) // set message data length SetDataLength(dataLength uint32) }
func NewMessage ¶
type MessageHandler ¶
type MessageHandler interface { // execute handler function ExecHandler(request Request) // add router AddRouter(msgType uint32, router Router) // start work pool StartWorkPool() // send message to task queue, the message would be handled by worker SendMsgToTaskQueue(Request) String() }
func NewMessageHandler ¶
func NewMessageHandler() MessageHandler
type Request ¶
type Request interface { // get request belong connection GetConnection() Connection // get custom message type which was bound on handler GetMsgDataType() uint32 // get message data GetMsgData() []byte }
type Server ¶
type Server interface { Context() context.Context // get message type GetMsgType() int // get connection manager ConnectionManager() ConnectionManager MessageHandler() MessageHandler // set a function it would be called on http request arrive SetOnInit(func(context.Context)) // set a function it would be called on a connection openning SetOnConnOpen(func(conn Connection) error) // set a function it would be called on a connection closing SetOnConnClose(func(conn Connection)) // call this function on http request arrive CallOnInit(context.Context) // call this function on connection openning CallOnConnOpen(Connection) error // call this function on connection closing CallOnConnClose(Connection) }
Click to show internal directories.
Click to hide internal directories.