Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
BaseRouter 实现router时,先嵌入这个基类,然后根据需要对这个基类的方法进行重写
func (*BaseRouter) PostHandle ¶
func (br *BaseRouter) PostHandle(ctx context.Context, req IRequest)
type IConnHandler ¶
type IConnHandler interface { HandleClose(*melody.Session, int, string) error HandleConnect(*melody.Session) HandleDisconnect(*melody.Session) HandleError(*melody.Session, error) HandleMessage(*melody.Session, []byte) HandleMessageBinary(*melody.Session, []byte) HandlePong(*melody.Session) HandleSentMessage(*melody.Session, []byte) HandleSentMessageBinary(*melody.Session, []byte) HandleRequest(w http.ResponseWriter, r *http.Request) error HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, keys map[string]interface{}) error HandleHttpRequest(r *ghttp.Request) }
IConnHandler Caller implements this interface to handle websocket connection.
type IMessage ¶
type IMessage interface { GetDataLen() uint32 //获取消息数据段长度 GetData() []byte //获取消息内容 GetBizType() string //获取消息内容 }
将请求的一个消息封装到message中,定义抽象层接口
type IMsgHandler ¶
type IMsgHandler interface { DoMsgHandler(ctx context.Context, request IRequest) //马上以非阻塞方式处理消息 AddRouter(ctx context.Context, bizType string, router IRouter) //为消息添加具体的处理逻辑 StartWorkerPool(ctx context.Context) //启动worker工作池 SendMsgToTaskQueue(request IRequest) (err error) //将消息交给TaskQueue,由worker进行处理 HandleMsg(ctx context.Context, request IRequest) //综合处理消息 }
IMsgHandler 消息管理抽象层
type IRequest ¶
type IRequest interface { GetSession() *melody.Session //获取请求连接信息 GetData() []byte //获取请求消息的数据 GetBizType() string //获取请求的消息ID GetMelody() *melody.Melody //获取当前melody Get(key string) (value interface{}, exist bool) //获取当前玩家信息 }
IRequest 接口: 实际上是把客户端请求的链接信息 和 请求的数据 包装到了 Request里
Click to show internal directories.
Click to hide internal directories.