Documentation ¶
Index ¶
- type Agent
- func (a *Agent) Close()
- func (a *Agent) Destroy()
- func (a *Agent) GetAdapter() IAgentAdapter
- func (a *Agent) IsAuth() bool
- func (a *Agent) LocalAddr() net.Addr
- func (a *Agent) OnClose()
- func (a *Agent) RemoteAddr() net.Addr
- func (a *Agent) Run()
- func (a *Agent) SendMessage(payload []byte) error
- func (a *Agent) SetToken(token string)
- func (a *Agent) SetUID(uid uint64)
- func (a *Agent) Token() string
- func (a *Agent) UID() uint64
- type AgentAdapter
- func (a *AgentAdapter) Codec() codec.Codec
- func (a *AgentAdapter) Conn() IConn
- func (a *AgentAdapter) GenID() uint32
- func (a *AgentAdapter) GetSequenceID() uint32
- func (a *AgentAdapter) ReadMessage() (interface{}, error)
- func (a *AgentAdapter) SetCodec(c codec.Codec)
- func (a *AgentAdapter) SetConn(conn IConn)
- func (a *AgentAdapter) Setup(conn IConn, codec codec.Codec)
- func (a *AgentAdapter) WriteMessage(payload interface{}) error
- type AgentCloseFunc
- type AgentCreateFunc
- type AgentManager
- type IAgent
- type IAgentAdapter
- type IClient
- type IConn
- type IServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent base agent struct
func (*Agent) Run ¶
func (a *Agent) Run()
Run agent start run usage func (a *Agent) Run (
for { data, err := a.ReadMessage() if err != nil { log.Debug("read message: %v", err) break } out := make(map[string]interface{}) if err := a.Codec().Unmarshal(data, &out, nil); err == nil { log.Info("receive message %v", out) out["seq"] = out["seq"].(float64) + 1 } else { log.Error(err) } a.WriteMessage(out) }
}
func (*Agent) SendMessage ¶
SendMessage send message to conn
type AgentAdapter ¶
type AgentAdapter struct {
// contains filtered or unexported fields
}
AgentAdapter agent adapter
func (*AgentAdapter) GetSequenceID ¶
func (a *AgentAdapter) GetSequenceID() uint32
GetSequenceID get inc id
func (*AgentAdapter) ReadMessage ¶
func (a *AgentAdapter) ReadMessage() (interface{}, error)
ReadMessage goroutine not safe
func (*AgentAdapter) Setup ¶
func (a *AgentAdapter) Setup(conn IConn, codec codec.Codec)
Setup AgentAdapter
func (*AgentAdapter) WriteMessage ¶
func (a *AgentAdapter) WriteMessage(payload interface{}) error
WriteMessage to connection
type AgentCreateFunc ¶
AgentCreateFunc create agent func
type AgentManager ¶
type AgentManager struct {
// contains filtered or unexported fields
}
AgentManager manager agent
func (*AgentManager) AddAgent ¶
func (am *AgentManager) AddAgent(a IAgent)
AddAgent add agent to manager
func (*AgentManager) GetAuthAgent ¶
func (am *AgentManager) GetAuthAgent(uid uint64) (IAgent, bool)
GetAuthAgent get auth agent,if exist return agent and true,else return false
func (*AgentManager) RemoveAgent ¶
func (am *AgentManager) RemoveAgent(a IAgent)
RemoveAgent remove agent from manager
type IAgent ¶
type IAgent interface { Run() OnClose() LocalAddr() net.Addr RemoteAddr() net.Addr Close() Destroy() UID() uint64 SetUID(uint64) Token() string SetToken(string) IsAuth() bool GetAdapter() IAgentAdapter SendMessage(payload []byte) error }
IAgent agent interface define
type IAgentAdapter ¶
type IAgentAdapter interface { //Setup AgentAdapter Setup(conn IConn, codec codec.Codec) //ReceiveMessage process request and notify message ReceiveMessage(payload interface{}) error //WriteMessage to connection WriteMessage(payload interface{}) error //ReadMessage goroutine not safe ReadMessage() (interface{}, error) // Codec get codec Codec() codec.Codec //SetCodec set codec SetCodec(c codec.Codec) //Conn get conn Conn() IConn // SetConn set conn SetConn(conn IConn) //GetSequence get inc id GetSequenceID() uint32 //OnClose agent close and clear OnClose() //GenID gen inc id GenID() uint32 }
IAgentAdapter agent adapter interface
type IConn ¶
type IConn interface { //ReadMessage read message/[]byte from conn ReadMessage() (interface{}, error) //WriteMessage write message/[]byte to conn WriteMessage(args ...interface{}) error //LocalAddr get local addr LocalAddr() net.Addr //RemoteAddr get remote addr RemoteAddr() net.Addr //Close conn Close() //Destory conn Destroy() }
IConn define network conn interface
Click to show internal directories.
Click to hide internal directories.