Documentation ¶
Index ¶
- Constants
- Variables
- type Codec
- type Conn
- type ConsoleLog
- type Context
- type DefaultCodec
- type Event
- type EventHandler
- type Group
- type IdGenerator
- type Logger
- type MessageKey
- type MiddlewareFunc
- type Options
- type Packet
- type Router
- type Server
- func (s *Server) Close()
- func (s *Server) Group(m ...MiddlewareFunc) (g *Group)
- func (s *Server) Handler(e string) EventHandler
- func (s *Server) On(e string, fn EventHandler)
- func (s *Server) SetLog(log Logger)
- func (e *Server) SetRouter(event string, router Router)
- func (s *Server) Start()
- func (s *Server) Use(middleware ...MiddlewareFunc)
Constants ¶
View Source
const ( MaxWorkId = -1 ^ (-1 << numWorkerBits) MaxSequence = -1 ^ (-1 << numSequenceBits) )
Variables ¶
View Source
var ( ErrorMustBePointer = errors.New("value must be a pointer") ErrorWrongRequestType = errors.New("value must be a string/[]byte/struct") ErrorWrongResponseType = errors.New("value must be a pointer of string/[]byte/struct") )
View Source
var ( ErrConnClosing = errors.New("use of closed network connection") ErrMessageTimeout = errors.New("timeout") )
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface { Encode(v interface{}) (msg []byte, err error) Decode(reply []byte, r interface{}) (err error) }
func NewDefaultCodec ¶
func NewDefaultCodec() Codec
type Conn ¶
type Conn interface { Id() string IsClosed() bool Close() Get(key string) interface{} Set(key string, value interface{}) RemoteAddr() net.Addr Emit(event string, v interface{}) error Ack(event string, v interface{}, r interface{}) error BroadcastToAll(event string, msg []byte) BroadcastTo(room, event string, msg []byte) Join(room string) Leave(room string) }
type ConsoleLog ¶
type ConsoleLog struct {
// contains filtered or unexported fields
}
func NewConsoleLog ¶
func NewConsoleLog() *ConsoleLog
func (ConsoleLog) Debug ¶
func (d ConsoleLog) Debug(v ...interface{})
func (ConsoleLog) Error ¶
func (d ConsoleLog) Error(v ...interface{})
func (ConsoleLog) Fatal ¶
func (d ConsoleLog) Fatal(v ...interface{})
func (ConsoleLog) Info ¶
func (d ConsoleLog) Info(v ...interface{})
func (ConsoleLog) Panic ¶
func (d ConsoleLog) Panic(v ...interface{})
func (ConsoleLog) Warn ¶
func (d ConsoleLog) Warn(v ...interface{})
type Context ¶
type Context interface { Id() string IsClosed() bool Close() Get(key string) interface{} Set(key string, value interface{}) RemoteAddr() net.Addr Emit(event string, v interface{}) error Ack(event string, v interface{}, r interface{}) error BroadcastToAll(event string, msg []byte) BroadcastTo(room, event string, msg []byte) Join(room string) Leave(room string) Content() []byte Packet() Packet Bind(v interface{}) error Reply(v interface{}) error Conn() Conn Logger() Logger }
type DefaultCodec ¶
type DefaultCodec struct { }
func (*DefaultCodec) Decode ¶
func (c *DefaultCodec) Decode(reply []byte, r interface{}) (err error)
func (*DefaultCodec) Encode ¶
func (c *DefaultCodec) Encode(v interface{}) (msg []byte, err error)
type EventHandler ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) Group ¶
func (g *Group) Group(middleware ...MiddlewareFunc) (sg *Group)
func (*Group) Handler ¶
func (g *Group) Handler(e string) EventHandler
func (*Group) On ¶
func (g *Group) On(e string, fn EventHandler)
func (*Group) Use ¶
func (g *Group) Use(middleware ...MiddlewareFunc)
type IdGenerator ¶
type IdGenerator struct {
// contains filtered or unexported fields
}
func NewSnowFlake ¶
func NewSnowFlake(workerId uint16) (*IdGenerator, error)
New returns a new snowflake node that can be used to generate snowflake
func (*IdGenerator) Generate ¶
func (sf *IdGenerator) Generate() uint64
Next creates and returns a unique snowflake ID
type Logger ¶
type Logger interface { Info(v ...interface{}) Debug(v ...interface{}) Warn(v ...interface{}) Error(v ...interface{}) Fatal(v ...interface{}) Panic(v ...interface{}) }
type MessageKey ¶
type MessageKey = uint16
const ( MessageKeyHeartbeat MessageKey = 0xffff // MessageKeyHeartbeat heartbeat message MessageKeyEmit MessageKey = iota // MessageKeyEmit Emit request, no response MessageKeyAckRequest // MessageKeyAckRequest Emit request, wait for response (ack) MessageKeyAckResponse // MessageKeyAckResponse ack response )
type MiddlewareFunc ¶
type MiddlewareFunc func(EventHandler) EventHandler
type Options ¶
type Options struct { // common WorkId uint16 Address string PacketSendChanLimit uint32 PacketReceiveChanLimit uint32 MessageTimeout time.Duration Codec Codec Logger Logger // only for server HeartbeatTimeout time.Duration }
func DefaultOptions ¶
func DefaultOptions() *Options
type Packet ¶
type Packet interface { Serialize() []byte Key() uint16 Id() uint64 Event() string Body() []byte NewReplyPacket(data []byte) Packet }
func NewHeartbeatPacket ¶
func NewHeartbeatPacket() Packet
type Router ¶
type Router interface { Use(args ...MiddlewareFunc) On(e string, fn EventHandler) Handler(e string) EventHandler // contains filtered or unexported methods }
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Group ¶
func (s *Server) Group(m ...MiddlewareFunc) (g *Group)
func (*Server) Handler ¶
func (s *Server) Handler(e string) EventHandler
func (*Server) On ¶
func (s *Server) On(e string, fn EventHandler)
func (*Server) Use ¶
func (s *Server) Use(middleware ...MiddlewareFunc)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.