Documentation ¶
Overview ¶
server
Index ¶
- Constants
- Variables
- func MyLog() *log.Entry
- func SendAllGateWay(resMap map[string]*Response, msg interface{})
- func SendAllGateWayPool(gatewayPools map[string]Pool, msg interface{})
- func SetLogFormat(format string)
- type Channel
- func (channel *Channel) Block(client *Response, blockClientId uint64)
- func (channel *Channel) BlockUid(uid int32, blockUid int32)
- func (channel *Channel) Publish(client *Response, message interface{})
- func (channel *Channel) Subscribe(client *Response)
- func (channel *Channel) UnSubscribe(client *Response)
- type Client
- type ClientData
- type ClientDataStruct
- type Conn
- type Factory
- type GateWayProtocol
- func (gateway *GateWayProtocol) Analyze(client *Response) (err error)
- func (gateway *GateWayProtocol) Decode(buf []byte) (err error)
- func (gateway *GateWayProtocol) Encode(msg interface{}) (buf []byte, err error)
- func (gateway *GateWayProtocol) GetCmd() (cmd uint16)
- func (req *GateWayProtocol) New() (protocol IProtocol)
- func (gateway *GateWayProtocol) SetCmd(cmd uint16)
- type Gateway
- type GatewayHeader
- type GatewayParamsHeader
- type GatewayWebsocket
- type Handler
- type HandlerFunc
- type IProtocol
- type MsgList
- type OpcodeHandler
- type PillProtocol
- func (req *PillProtocol) Analyze(client *Response) (err error)
- func (req *PillProtocol) Decode(buf []byte) (err error)
- func (req *PillProtocol) Encode(msg interface{}) (buf []byte, err error)
- func (req *PillProtocol) GetCmd() (cmd uint16)
- func (req *PillProtocol) New() (protocol IProtocol)
- func (req *PillProtocol) SetCmd(cmd uint16)
- type PillProtocolHeader
- type Pool
- type PoolConn
- type ProtocalError
- type Response
- type ServeRouter
- type Server
- type ServerHandler
- type TextProtocol
- type WebSocketHeader
- type WebSocketProtocol
- func (websocket *WebSocketProtocol) Analyze(client *Response) (err error)
- func (req *WebSocketProtocol) Decode(buf []byte) (err error)
- func (gateway *WebSocketProtocol) Encode(msg interface{}) (buf []byte, err error)
- func (req *WebSocketProtocol) GetCmd() (cmd uint16)
- func (this *WebSocketProtocol) Handshake(client *Response) (bool, []byte)
- func (this *WebSocketProtocol) New() (protocol IProtocol)
- func (req *WebSocketProtocol) SetCmd(cmd uint16)
- type Worker
- type WorkerClient
Constants ¶
const GATEWAY_VERSION uint8 = 0x01
const PILL_VERSION uint8 = 0x01
const PROTO_HEADER_FIRSTCHAR = 0x7f
const Protocal_Error_TYPE_COMMON uint8 = 1
const Protocal_Error_TYPE_DISCONNECT uint8 = 2
const SYS_BIND_UID uint16 = 0x0033
const SYS_CLIENT_DISCONNECT uint16 = 0x0006
const SYS_CLIENT_DISCONNECT_WORKER uint16 = 0x0042
const SYS_CONNECT_HANDSHAKE_ERROR uint16 = 0X0003
const SYS_CONNECT_MARK_ERROR uint16 = 0X0001
const SYS_CONNECT_SIZE_ERROR uint16 = 0X0002
const SYS_CONNECT_WORKER_ERROR uint16 = 0X0004
const SYS_GET_ALL_CLIENT_INFO uint16 = 0x0031
const SYS_GET_CLIENT_COUNT_BY_GROUP uint16 = 0x0040
const SYS_GET_CLIENT_ID_BY_UID uint16 = 0x0041
const SYS_GET_CLINET_INFO_BY_GROUP uint16 = 0x0039
const SYS_IS_ONLINE uint16 = 0x0032
const SYS_JOIN_GROUP uint16 = 0x0036
const SYS_KICK uint16 = 0x0008
const SYS_LEAVE_GROUP uint16 = 0x0037
const SYS_ON_BAN uint16 = 0X0015 //禁言
const SYS_ON_BLACK uint16 = 0X0017 //黑名单
const SYS_ON_BLOCK uint16 = 0X0014 //屏蔽
const SYS_ON_CLIENTIN uint16 = 0X0019 //广播进入
const SYS_ON_CLIENTOUT uint16 = 0X0020 //广播退出
const SYS_ON_CLOSE uint16 = 0X0012
const SYS_ON_CONNECT uint16 = 0X0010
const SYS_ON_HANDSHAKE uint16 = 0X0013
const SYS_ON_HEARTBEAT uint16 = 0X0018 //心跳
const SYS_ON_KICK uint16 = 0X0016 //踢
const SYS_ON_MESSAGE uint16 = 0X0011
const SYS_SEND_TO_ALL uint16 = 0x0009
const SYS_SEND_TO_GROUP uint16 = 0x0038
const SYS_SEND_TO_ONE uint16 = 0x0007
const SYS_SEND_TO_UID uint16 = 0x0035
const SYS_UNBIND_UID uint16 = 0x0034
const SYS_UPDATE_SESSION uint16 = 0x0030
const SYS_WORKER_DISCONNECT uint16 = 0x0005
Variables ¶
var ( //黑名单 BlackIdMap = make(map[int32]bool) AdminIdMap = make(map[int32]bool) //最近聊天内容纪录 RecentMsgChan = NewMsgList(256) )
var ( //GatewayPools map[string]Pool = make(map[string]Pool) WorkerClients = make(map[uint64]*WorkerClient) Gateways map[string]*Response = make(map[string]*Response) )
var (
DefaultHammerTime time.Duration = 60 * time.Second
)
var ( // ErrClosed is the error resulting if the pool is closed via pool.Close(). ErrClosed = errors.New("pool is closed") )
Functions ¶
func SendAllGateWay ¶
func SendAllGateWayPool ¶
func SetLogFormat ¶
func SetLogFormat(format string)
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func NewChannel ¶
func (*Channel) UnSubscribe ¶
type ClientData ¶
type ClientDataStruct ¶
type Conn ¶
type Conn struct { Id uint64 HandshakeFlg bool //是否已经通过握手验证 // contains filtered or unexported fields }
A conn represents the server side of connection.
type GateWayProtocol ¶
type GateWayProtocol struct { Header *GatewayHeader //IPHeader *GatewayParamsHeader //IP []byte //DataHeader *GatewayParamsHeader Content []byte }
func NewGatewayProtocol ¶
func NewGatewayProtocol() (protocol *GateWayProtocol)
func (*GateWayProtocol) Analyze ¶
func (gateway *GateWayProtocol) Analyze(client *Response) (err error)
func (*GateWayProtocol) Decode ¶
func (gateway *GateWayProtocol) Decode(buf []byte) (err error)
func (*GateWayProtocol) Encode ¶
func (gateway *GateWayProtocol) Encode(msg interface{}) (buf []byte, err error)
func (*GateWayProtocol) GetCmd ¶
func (gateway *GateWayProtocol) GetCmd() (cmd uint16)
func (*GateWayProtocol) New ¶
func (req *GateWayProtocol) New() (protocol IProtocol)
func (*GateWayProtocol) SetCmd ¶
func (gateway *GateWayProtocol) SetCmd(cmd uint16)
type Gateway ¶
type Gateway struct { InnerAddr string OuterAddr string OuterProtocol IProtocol InnerServer *Server OuterServer *Server EtcdClient *etcd.Client GatewayName string WatchName string }
func NewGateway ¶
func (*Gateway) ConnectWorkers ¶
func (gateway *Gateway) ConnectWorkers()
type GatewayHeader ¶
type GatewayParamsHeader ¶
将来以此为核心,讲gatewayprams作为一个数组,将获取到的值放入一个map中
type GatewayWebsocket ¶
type GatewayWebsocket struct { InnerAddr string OuterAddr string OuterProtocol IProtocol InnerServer *Server OuterServer *Server EtcdClient *etcd.Client GatewayName string WatchName string }
func (*GatewayWebsocket) Init ¶
func (gateway *GatewayWebsocket) Init()
type HandlerFunc ¶
这里将HandlerFunc定义为一个函数类型,因此以后当调用a = HandlerFunc(f)之后, 调用a的serve实际上就是调用f的对应方法, 拥有相同参数和相同返回值的函数属于同一种类型。
func (HandlerFunc) Serve ¶
func (f HandlerFunc) Serve(w *Response, r IProtocol)
Serve calls f(w, r).
type OpcodeHandler ¶
type OpcodeHandler struct {
// contains filtered or unexported fields
}
type PillProtocol ¶
type PillProtocol struct { Header *PillProtocolHeader Content []byte }
func NewPillProtocol ¶
func NewPillProtocol() (protocol *PillProtocol)
func (*PillProtocol) Analyze ¶
func (req *PillProtocol) Analyze(client *Response) (err error)
func (*PillProtocol) Decode ¶
func (req *PillProtocol) Decode(buf []byte) (err error)
func (*PillProtocol) Encode ¶
func (req *PillProtocol) Encode(msg interface{}) (buf []byte, err error)
func (*PillProtocol) GetCmd ¶
func (req *PillProtocol) GetCmd() (cmd uint16)
func (*PillProtocol) New ¶
func (req *PillProtocol) New() (protocol IProtocol)
func (*PillProtocol) SetCmd ¶
func (req *PillProtocol) SetCmd(cmd uint16)
type PillProtocolHeader ¶
type Pool ¶
type Pool interface { // Get returns a new connection from the pool. Closing the connections puts // it back to the Pool. Closing it when the pool is destroyed or full will // be counted as an error. Get() (*PoolConn, error) // Close closes the pool and all its connections. After Close() the pool is // no longer usable. Close() // Len returns the current number of connections of the pool. Len() int }
Pool interface describes a pool implementation. A pool should have maximum capacity. An ideal pool is threadsafe and easy to use.
func NewChannelPool ¶
NewChannelPool returns a new pool based on buffered channels with an initial capacity and maximum capacity. Factory is used when initial capacity is greater than zero to fill the pool. A zero initialCap doesn't fill the Pool until a new Get() is called. During a Get(), If there is no new connection available in the pool, a new connection will be created via the Factory() method.
type PoolConn ¶
type PoolConn struct {
// contains filtered or unexported fields
}
PoolConn is a wrapper around net.Conn to modify the the behavior of net.Conn's Close() method.
func (*PoolConn) MarkUnusable ¶
func (p *PoolConn) MarkUnusable()
MarkUnusable() marks the connection not usable any more, to let the pool close it instead of returning it to pool.
type ProtocalError ¶
type ProtocalError struct {
// contains filtered or unexported fields
}
func (*ProtocalError) Error ¶
func (e *ProtocalError) Error() string
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
A response represents the server side of aresponse.
func GetResponse ¶
func (*Response) SendContent ¶
type ServeRouter ¶
type ServeRouter struct {
// contains filtered or unexported fields
}
func NewServeRouter ¶
func NewServeRouter() *ServeRouter
NewServeRouter allocates and returns a new ServeRouter.
func (*ServeRouter) Handle ¶
func (router *ServeRouter) Handle(name uint16, handler Handler)
将router对应的opcode,方法存储
func (*ServeRouter) Serve ¶
func (router *ServeRouter) Serve(w *Response, r IProtocol)
取出opcode对应的操作方法,然后回调
type Server ¶
type Server struct { Addr string // TCP address to listen on, ":http" if empty Handler Handler // handler to invoke, http.DefaultServeMux if nil Protocol IProtocol // ErrorLog specifies an optional logger for errors accepting // connections and unexpected behavior from handlers. // If nil, logging goes to os.Stderr via the log package's // standard logger. ErrorLog *log.Logger }
func NewGatewayClient ¶
func (*Server) HandleFunc ¶
注册路由相应处理方法
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":5917" is used.
func (*Server) ListenAndServeUdp ¶
type ServerHandler ¶
type ServerHandler struct {
// contains filtered or unexported fields
}
用来获得当前的router并回调相应的处理方法
type TextProtocol ¶
type TextProtocol struct {
Content []byte
}
func (*TextProtocol) Analyze ¶
func (req *TextProtocol) Analyze(client *Response) (err error)
func (*TextProtocol) Decode ¶
func (req *TextProtocol) Decode(buf []byte) (err error)
func (*TextProtocol) Encode ¶
func (req *TextProtocol) Encode(msg interface{}) (buf []byte, err error)
func (*TextProtocol) GetCmd ¶
func (req *TextProtocol) GetCmd() (cmd uint16)
func (*TextProtocol) New ¶
func (req *TextProtocol) New() (protocol IProtocol)
type WebSocketHeader ¶
type WebSocketProtocol ¶
type WebSocketProtocol struct { Header *WebSocketHeader Content []byte }
func (*WebSocketProtocol) Analyze ¶
func (websocket *WebSocketProtocol) Analyze(client *Response) (err error)
func (*WebSocketProtocol) Decode ¶
func (req *WebSocketProtocol) Decode(buf []byte) (err error)
func (*WebSocketProtocol) Encode ¶
func (gateway *WebSocketProtocol) Encode(msg interface{}) (buf []byte, err error)
func (*WebSocketProtocol) GetCmd ¶
func (req *WebSocketProtocol) GetCmd() (cmd uint16)
func (*WebSocketProtocol) Handshake ¶
func (this *WebSocketProtocol) Handshake(client *Response) (bool, []byte)
func (*WebSocketProtocol) New ¶
func (this *WebSocketProtocol) New() (protocol IProtocol)
func (*WebSocketProtocol) SetCmd ¶
func (req *WebSocketProtocol) SetCmd(cmd uint16)
type Worker ¶
type WorkerClient ¶
type WorkerClient struct {
IP string
}