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 RegisterHttpMeta(meta *HttpMeta)
- func SessionQueuedCall(ses Session, callback func())
- type CloseReason
- type Codec
- type ContextSet
- type Error
- type Event
- type EventCallback
- type EventHooker
- type EventQueue
- type GenericPeer
- type HTTPAcceptor
- type HTTPConnector
- type HTTPSession
- type HttpMeta
- type MessageMeta
- type MessageTransmitter
- type Peer
- type PeerProperty
- type Pipe
- type RawPacket
- type RecvMsgEvent
- 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
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 MessageToName ¶
func MessageToName(msg interface{}) string
func MessageToString ¶
func MessageToString(msg interface{}) string
func NewErrorContext ¶
func RegisterHttpMeta ¶
func RegisterHttpMeta(meta *HttpMeta)
func SessionQueuedCall ¶
func SessionQueuedCall(ses Session, callback func())
在会话对应的Peer上的事件队列中执行callback,如果没有队列,则马上执行
Types ¶
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 MimeType() string }
type ContextSet ¶
type ContextSet interface { SetContext(key interface{}, v interface{}) GetContext(key interface{}) (interface{}, bool) 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, raw interface{}) (interface{}, error) }
HTTP连接器接口
type HTTPSession ¶
type HttpMeta ¶
type HttpMeta struct { Path string // 相对路径 Method string // 方式 RequestCodec Codec // 请求消息编码 RequestType reflect.Type // 请求消息类型 ResponseCodec Codec // 响应消息编码 ResponseType reflect.Type // 响应消息类型 }
消息元信息
func HttpMetaByMethodURL ¶
func (*HttpMeta) RequestTypeName ¶
func (*HttpMeta) ResponseTypeName ¶
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(name string) (interface{}, bool)
获取meta对应的名字绑定上下文
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 Peer ¶
type Peer interface { // 开启端,传入地址 Start() Peer // 停止通讯端 Stop() // Peer的类型(protocol.type),例如tcp.Connector/udp.Acceptor TypeName() string }
端, 可通过接口查询获得更多接口支持,如PeerProperty,ContextSet, SessionAccessor
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 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 SetHttps(certfile, keyfile string) // 访问会话 SessionAccessor }
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
|
|
Click to show internal directories.
Click to hide internal directories.