Documentation ¶
Index ¶
- Constants
- Variables
- type Acceptor
- type Agent
- type Channel
- type ChannelMap
- type ChannelMapImpl
- type Client
- type Conn
- type Context
- type ContextImpl
- func (c *ContextImpl) Dispatch(body proto.Message, recs ...*Location) error
- func (c *ContextImpl) Header() *pkt.Header
- func (c *ContextImpl) Next()
- func (c *ContextImpl) ReadBody(val proto.Message) error
- func (c *ContextImpl) Resp(status pkt.Status, body proto.Message) error
- func (c *ContextImpl) RespWithError(status pkt.Status, err error) error
- func (c *ContextImpl) Session() Session
- type Dialer
- type DialerContext
- type Dispatcher
- type Event
- type Frame
- type FuncTree
- type Handler
- type HandlerFunc
- type HandlersChain
- type Location
- type MessageListener
- type OpCode
- type Router
- type Server
- type Service
- type ServiceRegistration
- type Session
- type SessionStorage
- type StateListener
Constants ¶
Variables ¶
var ErrSessionNil = errors.New("err:session nil")
ErrNil
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶
type Acceptor interface { // Accept 返回一个握手完成的Channel对象或者一个error。 // 业务层需要处理不同协议和网络环境的下连接握手协议 Accept(Conn, time.Duration) (string, error) }
Acceptor 连接接收器
type Channel ¶
type Channel interface { Conn Agent Close() error //overwrite net.Conn.Close() ReadLoop(MessageListener) error SetWriteWait(time.Duration) SetReadWait(time.Duration) }
Channel 上层通用逻辑的封装
func NewChannel ¶
type ChannelMap ¶
type ChannelMap interface { Add(Channel) Remove(id string) Get(id string) (Channel, bool) All() []Channel }
ChannelMap ChannelMap
func NewChannelMap ¶
func NewChannelMap(num int) ChannelMap
type ChannelMapImpl ¶
type ChannelMapImpl struct {
// contains filtered or unexported fields
}
func (*ChannelMapImpl) Add ¶
func (c *ChannelMapImpl) Add(channel Channel)
Add channel to channelMap
func (*ChannelMapImpl) All ¶
func (c *ChannelMapImpl) All() []Channel
func (*ChannelMapImpl) Remove ¶
func (c *ChannelMapImpl) Remove(id string)
type Conn ¶
type Conn interface { net.Conn ReadFrame() (Frame, error) WriteFrame(OpCode, []byte) error Flush() error }
Conn 对net.Conn进行二次封装,把读与写的操作封装到连接中
type Context ¶
type Context interface { Dispatcher SessionStorage Header() *pkt.Header ReadBody(val proto.Message) error Session() Session RespWithError(status pkt.Status, err error) error Resp(status pkt.Status, body proto.Message) error Dispatch(body proto.Message, revs ...*Location) error Next() }
Context 实现处理器中的上下文
func BuildContext ¶
func BuildContext() Context
type ContextImpl ¶
type ContextImpl struct { sync.Mutex Dispatcher SessionStorage // contains filtered or unexported fields }
ContextImpl is the most important part of him
func (*ContextImpl) Dispatch ¶
func (c *ContextImpl) Dispatch(body proto.Message, recs ...*Location) error
Dispatch 派发消息到指定的接收方
func (*ContextImpl) Header ¶
func (c *ContextImpl) Header() *pkt.Header
func (*ContextImpl) RespWithError ¶
func (c *ContextImpl) RespWithError(status pkt.Status, err error) error
func (*ContextImpl) Session ¶
func (c *ContextImpl) Session() Session
type DialerContext ¶
type Dispatcher ¶
Dispatcher 向网关中的channels两个连接推送一条消息LogicPkt 这个能力由容器提供
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
func (*Event) Fire ¶
Fire causes e to complete. It is safe to call multiple times, and concurrently. It returns true iff this call to Fire caused the signaling channel returned by Done to close. 用于触发事件,它通过sync.Once确保事件只会被触发一次, 使用atomic.StoreInt32()原子操作将fired标志位置为1,表示事件已经触发。 同时,它还会关闭通道c,以通知等待该事件的goroutine
type Frame ¶
type Frame interface { SetOpCode(OpCode) GetOpCode() OpCode SetPayload([]byte) GetPayload() []byte }
Frame 通过抽象一个Frame接口解决底层封包与拆包
type FuncTree ¶
type FuncTree struct {
// contains filtered or unexported fields
}
func (*FuncTree) Add ¶
func (t *FuncTree) Add(path string, handlers ...HandlerFunc)
type Handler ¶
type Handler interface { MessageListener Acceptor StateListener }
type MessageListener ¶
MessageListener 消息监听器
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) AddHandles ¶
func (r *Router) AddHandles(command string, handlers ...HandlerFunc)
AddHandles 添加handlers
func (*Router) Serve ¶
func (r *Router) Serve(pkt *pkt.LogicPkt, dispatcher Dispatcher, cache SessionStorage, session Session) error
type Server ¶
type Server interface { ServiceRegistration SetAcceptor(Acceptor) SetMessageListener(MessageListener) SetStateListener(StateListener) SetReadWait(time.Duration) SetChannelMap(ChannelMap) Start() error Push(string, []byte) error Shutdown(ctx context.Context) error }
Server 服务器用于承载Service
type ServiceRegistration ¶
type ServiceRegistration interface { Service // PublicAddress ip or domain PublicAddress() string PublicPort() int DialURL() string GetProtocol() string GetNamespace() string GetTags() []string // String SetTags(tags []string) // SetMeta(meta map[string]string) String() string }
ServiceRegistration Service define a Service
type Session ¶
type Session interface { GetChannelId() string GetGateId() string GetAccount() string GetZone() string GetIsp() string GetRemoteIP() string GetDevice() string GetApp() string GetTags() []string }
Session 会话
type SessionStorage ¶
type SessionStorage interface { // Add a session Add(session *pkt.Session) error // Delete a session Delete(account string, channelId string) error // Get session by channelId Get(channelId string) (*pkt.Session, error) // GetLocations Get Locations by accounts GetLocations(account ...string) ([]*Location, error) // GetLocation Get Location by account and device GetLocation(account string, device string) (*Location, error) }
SessionStorage 定义会话存储,提供基于保存、删除、查找会话的功能
type StateListener ¶
StateListener 状态监听器