Documentation ¶
Index ¶
- Variables
- type AuthHandler
- type ConnHandlerFunc
- type Connection
- type Context
- type Engine
- type Handler
- type HandlerChain
- type HandlerFunc
- type Manager
- type Option
- func WithAddr(addr string) Option
- func WithID(id string) Option
- func WithManagerSize(size int) Option
- func WithMaxConn(size int) Option
- func WithMaxMsgChanLen(size int) Option
- func WithMaxPacketSize(size int) Option
- func WithMaxWorkerTaskLen(size int) Option
- func WithName(n string) Option
- func WithOnConnAuth(f AuthHandler) Option
- func WithOnConnStart(f func(conn Connection)) Option
- func WithOnConnStop(f func(conn Connection)) Option
- func WithReadBufferSize(size int) Option
- func WithRouter(r *Engine) Option
- func WithWorkerPoolSize(size int) Option
- func WithWriteBufferSize(size int) Option
- func WithWriteWait(d time.Duration) Option
- type Options
- type Request
- type RouterGroup
- type Server
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrConnNotFound 连接未找到 ErrConnNotFound = errors.New("connection not found") // ErrConnNotFinish 连接未完成,不可以发送消息 ErrConnNotFinish = errors.New("connection not finish when send msg") )
Functions ¶
This section is empty.
Types ¶
type AuthHandler ¶
type ConnHandlerFunc ¶
type ConnHandlerFunc func(cid uint64, conn Connection) error
type Connection ¶
type Connection interface { Start() //启动连接,让当前连接开始工作 Stop() //停止连接,结束当前连接状态 Context() context.Context //返回ctx,用于用户自定义的go程获取连接退出状态 GetID() uint64 //获取当前连接ID GetUID() int //获取当前连接鉴权ID RemoteAddr() net.Addr //获取远程客户端地址信息 Send(ctx context.Context, mid int, data []byte) error //发送消息 AsyncSend(ctx context.Context, mid int, data []byte) error //异步发送消息 }
Connection 定义连接接口
func NewConnect ¶
func NewConnect(s *wsServer, conn *websocket.Conn, id uint64, uid int) Connection
NewConnect 创建连接的方法
type Context ¶
type Context struct { Req *Request // contains filtered or unexported fields }
Context 上下文对象
func (*Context) Deadline ¶
Deadline always returns that there is no deadline (ok==false), maybe you want to use Request.Context().Deadline() instead.
func (*Context) Done ¶
func (c *Context) Done() <-chan struct{}
Done always returns nil (chan which will wait forever), if you want to abort your work when the connection was closed you should use Request.Context().Done() instead.
type Engine ¶
type Engine struct { RouterGroup // contains filtered or unexported fields }
Engine 路由引擎
type Option ¶
type Option func(*Options)
func WithManagerSize ¶
func WithMaxConn ¶
func WithMaxMsgChanLen ¶
func WithMaxPacketSize ¶
func WithMaxWorkerTaskLen ¶
func WithOnConnAuth ¶
func WithOnConnAuth(f AuthHandler) Option
func WithOnConnStart ¶
func WithOnConnStart(f func(conn Connection)) Option
func WithOnConnStop ¶
func WithOnConnStop(f func(conn Connection)) Option
func WithReadBufferSize ¶
func WithRouter ¶
func WithWorkerPoolSize ¶
func WithWriteBufferSize ¶
func WithWriteWait ¶
type Options ¶
type Options struct { ID string //服务器ID Name string //服务器的名称 Addr string //服务绑定的地址 MaxPacketSize int //都需数据包的最大值 MaxConn int //当前服务器主机允许的最大链接个数 WorkerPoolSize int //业务工作Worker池的数量 MaxWorkerTaskLen int //业务工作Worker对应负责的任务队列最大任务存储数量 MaxMsgChanLen int //SendBuffMsg发送消息的缓冲最大长度 ManagerSize int //连接管理器个数 ReadBufferSize int //接收缓冲区 WriteBufferSize int //发送缓冲区 WriteWait time.Duration //写入客户端超时 Router *Engine //请求路由 OnConnStart func(conn Connection) //该Server的连接创建开始时Hook函数 OnConnStop func(conn Connection) //该Server的连接断开时的Hook函数 OnConnAuth AuthHandler //该Server的连接鉴权完成的Hook函数 }
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (Request) Conn ¶
func (r Request) Conn() Connection
type RouterGroup ¶
type RouterGroup struct { Handlers HandlerChain // contains filtered or unexported fields }
RouterGroup 路由组
func (*RouterGroup) AddRoute ¶
func (g *RouterGroup) AddRoute(event string, handlers ...HandlerFunc)
AddRoute specific middleware
type Server ¶
type Server interface { // Init Initialise options Init(...Option) // Options Retrieve the options Options() *Options // Start the server Start(ctx context.Context) error // Stop the server Stop(ctx context.Context) error // Endpoint return a real address to registry endpoint. Endpoint() (*url.URL, error) // GetManager 所有连接管理 GetManager(cid uint64) *Manager // Range 遍历所有连接 Range(f ConnHandlerFunc) // Total 服务器连接总数 Total() int }
Server is a simple micro server abstraction
Click to show internal directories.
Click to hide internal directories.