Documentation
¶
Index ¶
- func MessageMetaVisit(nameRule string, callback func(meta *MessageMeta) bool) error
- func MessageSize(msg interface{}) int
- func MessageToID(msg interface{}) int
- func MessageToName(msg interface{}) string
- func MessageToString(msg interface{}) string
- func NewError(s string) error
- func NewErrorContext(s string, context interface{}) error
- func QueuedCall(queue EventQueue, callback func())
- func SessionQueuedCall(ses Session, callback func())
- type CapturePanicNotifyFunc
- type CloseReason
- type Codec
- type ContextSet
- type Error
- type Event
- type EventCallback
- type EventHooker
- type EventQueue
- type GenericPeer
- type HTTPAcceptor
- type HTTPConnector
- type HTTPRequest
- type HTTPSession
- type MessageMeta
- func (self *MessageMeta) FullName() string
- func (self *MessageMeta) GetContext(key string) (interface{}, bool)
- func (self *MessageMeta) GetContextAsInt(name string, defaultValue int) int
- func (self *MessageMeta) GetContextAsString(key, defaultValue string) string
- func (self *MessageMeta) NewType() interface{}
- func (self *MessageMeta) SetContext(name string, data interface{}) *MessageMeta
- func (self *MessageMeta) TypeName() string
- type MessageTransmitter
- type MySQLConnector
- type MySQLOperator
- type Peer
- type PeerCaptureIOPanic
- type PeerProperty
- type PeerReadyChecker
- type Pipe
- type RawPacket
- type RecvMsgEvent
- type RedisConnector
- type RedisPoolOperator
- type SendMsgEvent
- type Session
- type SessionAccepted
- type SessionAccessor
- type SessionCloseNotify
- type SessionClosed
- type SessionConnectError
- type SessionConnected
- type SessionInit
- type TCPAcceptor
- type TCPConnector
- type TCPSocketOption
- type UDPAcceptor
- type UDPConnector
- type WSAcceptor
- type WSConnector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MessageMetaVisit ¶
func MessageMetaVisit(nameRule string, callback func(meta *MessageMeta) bool) error
func MessageSize ¶
func MessageSize(msg interface{}) int
func MessageToID ¶
func MessageToID(msg interface{}) int
func MessageToString ¶
func MessageToString(msg interface{}) string
func NewErrorContext ¶
func SessionQueuedCall ¶
func SessionQueuedCall(ses Session, callback func())
在会话对应的Peer上的事件队列中执行callback,如果没有队列,则马上执行
Types ¶
type CapturePanicNotifyFunc ¶
type CapturePanicNotifyFunc func(interface{}, EventQueue)
type CloseReason ¶
type CloseReason int32
const ( CloseReason_IO CloseReason = iota // 普通IO断开 CloseReason_Manual // 关闭前,调用过Session.Close )
func (CloseReason) String ¶
func (self CloseReason) String() string
type Codec ¶
type Codec interface {
// 将数据转换为字节数组
Encode(msgObj interface{}, ctx ContextSet) (data interface{}, err error)
// 将字节数组转换为数据
Decode(data interface{}, msgObj interface{}) error
// 编码器的名字
Name() string
// 兼容http类型
MimeType() string
}
编码包
type ContextSet ¶
type ContextSet interface {
// 为对象设置一个自定义属性
SetContext(key interface{}, v interface{})
// 从对象上根据key获取一个自定义属性
GetContext(key interface{}) (interface{}, bool)
// 给定一个值指针, 自动根据值的类型GetContext后设置到值
FetchContext(key, valuePtr interface{}) bool
}
设置和获取自定义属性
type Event ¶
type Event interface {
// 事件对应的会话
Session() Session
// 事件携带的消息
Message() interface{}
}
事件
type EventHooker ¶
type EventHooker interface {
// 入站(接收)的事件处理
OnInboundEvent(input Event) (output Event)
// 出站(发送)的事件处理
OnOutboundEvent(input Event) (output Event)
}
处理钩子(参数输入, 返回输出, 不给MessageProccessor处理时,可以将Event设置为nil)
type EventQueue ¶
type EventQueue interface {
// 事件队列开始工作
StartLoop() EventQueue
// 停止事件队列
StopLoop() EventQueue
// 等待退出
Wait()
// 投递事件, 通过队列到达消费者端
Post(callback func())
// 是否捕获异常
EnableCapturePanic(v bool)
}
事件队列
type HTTPAcceptor ¶
type HTTPAcceptor interface {
GenericPeer
// 设置http文件服务虚拟地址和文件系统根目录
SetFileServe(dir string, root string)
// 设置模板文件地址
SetTemplateDir(dir string)
// 设置http模板的分隔符,解决默认{{ }}冲突问题
SetTemplateDelims(delimsLeft, delimsRight string)
// 设置模板的扩展名,默认: .tpl .html
SetTemplateExtensions(exts []string)
// 设置模板函数入口
SetTemplateFunc(f []template.FuncMap)
}
type HTTPConnector ¶
type HTTPConnector interface {
GenericPeer
Request(method, path string, param *HTTPRequest) error
}
HTTP连接器接口
type HTTPRequest ¶
type HTTPSession ¶
type MessageMeta ¶
type MessageMeta struct {
Codec Codec // 消息用到的编码
Type reflect.Type // 消息类型, 注册时使用指针类型
ID int // 消息ID (二进制协议中使用)
// contains filtered or unexported fields
}
消息元信息
func (*MessageMeta) FullName ¶
func (self *MessageMeta) FullName() string
func (*MessageMeta) GetContext ¶
func (self *MessageMeta) GetContext(key string) (interface{}, bool)
获取meta对应的名字绑定上下文
func (*MessageMeta) GetContextAsInt ¶
func (self *MessageMeta) GetContextAsInt(name string, defaultValue int) int
按字符串格式取context
func (*MessageMeta) GetContextAsString ¶
func (self *MessageMeta) GetContextAsString(key, defaultValue string) string
按字符串格式取context
func (*MessageMeta) SetContext ¶
func (self *MessageMeta) SetContext(name string, data interface{}) *MessageMeta
为meta对应的名字绑定上下文
func (*MessageMeta) TypeName ¶
func (self *MessageMeta) TypeName() string
type MessageTransmitter ¶
type MessageTransmitter interface {
// 接收消息
OnRecvMessage(ses Session) (msg interface{}, err error)
// 发送消息
OnSendMessage(ses Session, msg interface{}) error
}
消息收发器
type MySQLConnector ¶
type MySQLOperator ¶
type MySQLOperator interface {
Operate(callback func(rawClient interface{}) interface{}) interface{}
}
type Peer ¶
type Peer interface {
// 开启端,传入地址
Start() Peer
// 停止通讯端
Stop()
// Peer的类型(protocol.type),例如tcp.Connector/udp.Acceptor
TypeName() string
}
端, 可通过接口查询获得更多接口支持,如PeerProperty,ContextSet, SessionAccessor
type PeerCaptureIOPanic ¶
type PeerCaptureIOPanic interface {
// 开启IO层异常捕获
EnableCaptureIOPanic(v bool)
// 获取当前异常捕获值
CaptureIOPanic() bool
}
开启IO层异常捕获,在生产版本对外端口应该打开此设置
type PeerProperty ¶
type PeerProperty interface {
Name() string
Address() string
Queue() EventQueue
// 设置名称(可选)
SetName(v string)
// 设置Peer地址
SetAddress(v string)
// 设置Peer挂接队列(可选)
SetQueue(v EventQueue)
}
Peer基础属性
type RecvMsgEvent ¶
type RecvMsgEvent struct {
Ses Session
Msg interface{}
}
接收到消息
func (*RecvMsgEvent) Message ¶
func (self *RecvMsgEvent) Message() interface{}
func (*RecvMsgEvent) Send ¶
func (self *RecvMsgEvent) Send(msg interface{})
func (*RecvMsgEvent) Session ¶
func (self *RecvMsgEvent) Session() Session
type RedisConnector ¶
type RedisConnector interface {
GenericPeer
// 设置密码
SetPassword(v string)
// 设置连接数
SetConnectionCount(v int)
// 设置库索引
SetDBIndex(v int)
}
type RedisPoolOperator ¶
type RedisPoolOperator interface {
// 获取
Operate(callback func(rawClient interface{}) interface{}) interface{}
}
type SendMsgEvent ¶
type SendMsgEvent struct {
Ses Session
Msg interface{} // 用户需要发送的消息
}
会话开始发送数据事件
func (*SendMsgEvent) Message ¶
func (self *SendMsgEvent) Message() interface{}
func (*SendMsgEvent) Session ¶
func (self *SendMsgEvent) Session() Session
type Session ¶
type Session interface {
// 获得原始的Socket连接
Raw() interface{}
// 获得Session归属的Peer
Peer() Peer
// 发送消息,消息需要以指针格式传入
Send(msg interface{})
// 断开
Close()
// 标示ID
ID() int64
}
长连接
type SessionAccepted ¶
type SessionAccepted struct {
}
func (*SessionAccepted) String ¶
func (self *SessionAccepted) String() string
func (*SessionAccepted) SystemMessage ¶
func (self *SessionAccepted) SystemMessage()
type SessionAccessor ¶
type SessionAccessor interface {
// 获取一个连接
GetSession(int64) Session
// 遍历连接
VisitSession(func(Session) bool)
// 连接数量
SessionCount() int
// 关闭所有连接
CloseAllSession()
}
会话访问
type SessionCloseNotify ¶
type SessionCloseNotify struct {
}
udp通知关闭,内部使用
func (*SessionCloseNotify) String ¶
func (self *SessionCloseNotify) String() string
func (*SessionCloseNotify) SystemMessage ¶
func (self *SessionCloseNotify) SystemMessage()
type SessionClosed ¶
type SessionClosed struct {
Reason CloseReason // 断开原因
}
func (*SessionClosed) String ¶
func (self *SessionClosed) String() string
func (*SessionClosed) SystemMessage ¶
func (self *SessionClosed) SystemMessage()
type SessionConnectError ¶
type SessionConnectError struct {
}
func (*SessionConnectError) String ¶
func (self *SessionConnectError) String() string
func (*SessionConnectError) SystemMessage ¶
func (self *SessionConnectError) SystemMessage()
type SessionConnected ¶
type SessionConnected struct {
}
func (*SessionConnected) String ¶
func (self *SessionConnected) String() string
func (*SessionConnected) SystemMessage ¶
func (self *SessionConnected) SystemMessage()
type SessionInit ¶
type SessionInit struct {
}
func (*SessionInit) String ¶
func (self *SessionInit) String() string
type TCPAcceptor ¶
type TCPAcceptor interface {
GenericPeer
// 访问会话
SessionAccessor
TCPSocketOption
// 查看当前侦听端口,使用host:0 作为Address时,socket底层自动分配侦听端口
Port() int
}
TCP接受器,具备会话访问
type TCPConnector ¶
type TCPConnector interface {
GenericPeer
TCPSocketOption
// 设置重连时间
SetReconnectDuration(time.Duration)
// 获取重连时间
ReconnectDuration() time.Duration
// 默认会话
Session() Session
// 设置会话管理器 实现peer.SessionManager接口
SetSessionManager(raw interface{})
// 查看当前连接使用的端口
Port() int
}
TCP连接器
type TCPSocketOption ¶
type TCPSocketOption interface {
// 收发缓冲大小,默认-1
SetSocketBuffer(readBufferSize, writeBufferSize int, noDelay bool)
// 设置最大的封包大小
SetMaxPacketSize(maxSize int)
// 设置读写超时,默认0,不超时
SetSocketDeadline(read, write time.Duration)
}
TCP
type UDPAcceptor ¶
type UDPAcceptor interface {
// 底层使用TTL做session生命期管理,超时时间越短,内存占用越低
SetSessionTTL(dur time.Duration)
}
UDP接受器
type WSAcceptor ¶
type WSAcceptor interface {
GenericPeer
// 访问会话
SessionAccessor
SetHttps(certfile, keyfile string)
// 设置升级器
SetUpgrader(upgrader interface{})
// 查看当前侦听端口,使用host:0 作为Address时,socket底层自动分配侦听端口
Port() int
}
Websocket接受器,具备会话访问
type WSConnector ¶
type WSConnector interface {
GenericPeer
// 设置重连时间
SetReconnectDuration(time.Duration)
// 获取重连时间
ReconnectDuration() time.Duration
// 默认会话
Session() Session
// 设置会话管理器 实现peer.SessionManager接口
SetSessionManager(raw interface{})
// 查看当前连接使用的端口
Port() int
}
Websocket连接器
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
gogopb/test
Package test is a generated protocol buffer package.
|
Package test is a generated protocol buffer package. |
|
examples
|
|
|
chat/client
command
|
|
|
chat/server
command
|
|
|
echo
command
|
|
|
fileserver
command
|
|
|
websocket
command
|
|
|
Generated by github.com/davyxu/protoplus DO NOT EDIT!
|
Generated by github.com/davyxu/protoplus DO NOT EDIT! |
|
Generated by github.com/davyxu/protoplus DO NOT EDIT!
|
Generated by github.com/davyxu/protoplus DO NOT EDIT! |
Click to show internal directories.
Click to hide internal directories.



