Documentation
¶
Index ¶
- Constants
- type Call
- type ConnConfig
- type ConnConfigOption
- func WithAddr(addr string) ConnConfigOption
- func WithBinaryPoolSize(min, max int) ConnConfigOption
- func WithHeartBeat(interval time.Duration) ConnConfigOption
- func WithMaxMsgNum(send, recv int32) ConnConfigOption
- func WithOnConnHandle(onConnHandle func(conn TcpConn) bool) ConnConfigOption
- func WithProto(p proto.Proto) ConnConfigOption
- func WithReadTimeout(d time.Duration) ConnConfigOption
- func WithReconnection(reconnection bool) ConnConfigOption
- func WithRecvBufferSize(size int32) ConnConfigOption
- func WithTLSConfig(tlsConfig *tls.Config) ConnConfigOption
- func WithWriteTimeout(d time.Duration) ConnConfigOption
- type Context
- func (c *Context) Abort()
- func (c *Context) Bind(dest any) error
- func (c *Context) GetCtx() context.Context
- func (c *Context) GetReqMsg() message.Message
- func (c *Context) GetReqMsgId() uint32
- func (c *Context) JSON(msgId uint32, src interface{}, meatData ...map[string]string) error
- func (c *Context) MarshallerType() codec.MarshalType
- func (c *Context) Next()
- func (c *Context) ProtoBuf(msgId uint32, src interface{}, meatData ...map[string]string) error
- func (c *Context) Raw(msgId uint32, src interface{}, meatData ...map[string]string) error
- func (c *Context) RawData() []byte
- func (c *Context) SetCtx(ctx context.Context)
- type MsgMiddleHandler
- type Mux
- type TcpClient
- func (t *TcpClient) Call(c context.Context, req message.Message) (resp message.Message, err error)
- func (t *TcpClient) Close()
- func (t *TcpClient) HandleHeartBeat(ctx *Context)
- func (t *TcpClient) HandlePush(ctx *Context)
- func (t *TcpClient) HandleReply(ctx *Context)
- func (t *TcpClient) IsClose() bool
- func (t *TcpClient) RegisterGlobalMiddle(middles ...func(ctx *Context))
- func (t *TcpClient) Start() error
- type TcpConn
- type TcpServer
- func (t *TcpServer) Close()
- func (t *TcpServer) HandleHeartBeat(ctx *Context)
- func (t *TcpServer) HandlePush(ctx *Context)
- func (t *TcpServer) HandleReply(ctx *Context)
- func (t *TcpServer) HandleRequest(ctx *Context)
- func (t *TcpServer) IsClosed() bool
- func (t *TcpServer) ListenAndServe(network, addr string) error
- func (t *TcpServer) RegisterGlobalMiddle(middles ...func(ctx *Context))
- func (t *TcpServer) RegisterHandler(id modelID, subID subMsgID, handler func(ctx *Context), ...)
- func (t *TcpServer) RegisterModelMiddle(id modelID, middles ...func(ctx *Context))
Constants ¶
const ABORT int8 = 100
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct {
Reply message.Message
Error error // After completion, the error status.
Done chan *Call // Strobes when call is complete.
// contains filtered or unexported fields
}
Call represents an active req.
type ConnConfig ¶
type ConnConfigOption ¶
type ConnConfigOption func(ConnConfig) ConnConfig
func WithBinaryPoolSize ¶
func WithBinaryPoolSize(min, max int) ConnConfigOption
WithBinaryPoolSize sets the binary pool size. default: min=512, max=512*1024
func WithHeartBeat ¶
func WithHeartBeat(interval time.Duration) ConnConfigOption
WithHeartBeat sets the heart beat.
func WithMaxMsgNum ¶
func WithMaxMsgNum(send, recv int32) ConnConfigOption
WithMaxMsgNum sets the max [send|recv] message number. default: send=1000, recv=10000
func WithOnConnHandle ¶
func WithOnConnHandle(onConnHandle func(conn TcpConn) bool) ConnConfigOption
WithOnConnHandle sets the onConnHandle.
func WithProto ¶
func WithProto(p proto.Proto) ConnConfigOption
WithProto sets the tcp server proto.
func WithReadTimeout ¶
func WithReadTimeout(d time.Duration) ConnConfigOption
WithReadTimeout sets the read timeout.
func WithReconnection ¶
func WithReconnection(reconnection bool) ConnConfigOption
WithReconnection sets the reconnection.
func WithRecvBufferSize ¶
func WithRecvBufferSize(size int32) ConnConfigOption
WithRecvBufferSize sets the recv buffer size.
func WithTLSConfig ¶
func WithTLSConfig(tlsConfig *tls.Config) ConnConfigOption
WithTLSConfig sets the tls config.
func WithWriteTimeout ¶
func WithWriteTimeout(d time.Duration) ConnConfigOption
WithWriteTimeout sets the write timeout.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContext ¶
func (*Context) JSON ¶
JSON Reply to client using json marshaller. Whatever ctx.Packx.Marshaller.MarshalName is 'json' or not , message block will marshal its header and body by json marshaller.
func (*Context) MarshallerType ¶
func (c *Context) MarshallerType() codec.MarshalType
MarshallerType 获取解析类型,请配合RawData使用
func (*Context) Next ¶
func (c *Context) Next()
Next Since middlewares are divided into 3 kinds: global, messageIDSelfRelated, anchorType, offset can't be used straightly to control middlewares like middlewares[offset](). Thus, c.Next() means actually do nothing.
func (*Context) ProtoBuf ¶
ProtoBuf Reply to client using protobuf marshaller. Whatever ctx.Packx.Marshaller.MarshalName is 'protobuf' or not , message block will marshal its header and body by protobuf marshaller.
func (*Context) Raw ¶
Raw Reply to client using protobuf marshaller. Whatever ctx.Packx.Marshaller.MarshalName is 'protobuf' or not , message block will marshal its header and body by protobuf marshaller.
type MsgMiddleHandler ¶
type MsgMiddleHandler struct {
// 模块中间件
ModelMiddles []func(ctx *Context)
// 消息处理函数
Handlers map[subMsgID]func(ctx *Context)
// 消息处理函数的中间件
HandlerMiddles map[subMsgID][]func(ctx *Context)
}
MsgMiddleHandler 模块处理函数
type Mux ¶
type Mux struct {
// 用于存储消息ID和消息处理函数的映射关系,key为模块ID,value为消息ID和消息处理函数的映射关系
Handlers map[modelID]*MsgMiddleHandler
// AllowAdd of allow routes to be added before starting.
// 只允许在启动前添加路由
AllowAdd bool
// global-middles
// 全局中间件
GlobalMiddles []func(ctx *Context)
}
Mux is a multiplexer for network connections. 是一个网络路由复用器
func (*Mux) RegisterGlobalMiddle ¶
RegisterGlobalMiddle add global routing middle handlers.
func (*Mux) RegisterHandler ¶
func (m *Mux) RegisterHandler(id modelID, subID subMsgID, handler func(ctx *Context), middles ...func(ctx *Context))
RegisterHandler add routing handlers by modelID and subMsgID.
func (*Mux) RegisterModelMiddle ¶
RegisterModelMiddle add routing middle handlers by modelID.
type TcpClient ¶
type TcpClient struct {
TcpConn
// contains filtered or unexported fields
}
func NewTcpClient ¶
func NewTcpClient(addr string, cfgOptions ...ConnConfigOption) *TcpClient
func (*TcpClient) HandleHeartBeat ¶
HandleHeartBeat 处理心跳消息
func (*TcpClient) RegisterGlobalMiddle ¶
RegisterGlobalMiddle add global routing middle handlers.
type TcpConn ¶
type TcpConn interface {
proto.Proto
net.Conn
// GetConnId returns the connection id.
GetConnId() uint64
SetConnId(uint64)
Start()
SendMsg(message.Message) error
// StopNotifyChan 关闭的时候,需要被通知
StopNotifyChan() chan struct{}
}
func NewTcpConn ¶
func NewTcpConn(conn *net.TCPConn, cfg ConnConfig, handleFunc func(ctx *Context)) TcpConn
type TcpServer ¶
type TcpServer struct {
// contains filtered or unexported fields
}
func NewTcpX ¶
func NewTcpX(cfgOptions ...ConnConfigOption) *TcpServer
func (*TcpServer) HandleHeartBeat ¶
HandleHeartBeat 处理心跳消息
func (*TcpServer) HandleRequest ¶
HandleRequest 处理请求消息
func (*TcpServer) ListenAndServe ¶
ListenAndServe Start to listen. Serve can decode stream generated by packx. Support tcp and udp
func (*TcpServer) RegisterGlobalMiddle ¶
RegisterGlobalMiddle add global routing middle handlers.
func (*TcpServer) RegisterHandler ¶
func (t *TcpServer) RegisterHandler(id modelID, subID subMsgID, handler func(ctx *Context), middles ...func(ctx *Context))
RegisterHandler add routing handlers by modelID and subMsgID.
func (*TcpServer) RegisterModelMiddle ¶
RegisterModelMiddle add routing middle handlers by modelID.