Versions in this module Expand all Collapse all v0 v0.1.0 Aug 7, 2022 Changes in this version + const IdleTime + var ErrClientClosed = errors.New("client closed") + var ErrServerClosed = errors.New("server closed idle connection") + func SetLogger(l Logger) + type CMD uint16 + const Ack + const All + const Heartbeat + const Single + type Codec interface + Decode func(data []byte, v interface{}) error + Encode func(v interface{}) ([]byte, error) + type Conn struct + func (c *Conn) Close() + func (c *Conn) GetClientIP() net.Addr + func (c *Conn) GetExtraMap(k string) interface{} + func (c *Conn) GetRawConn() net.Conn + func (c *Conn) SendAll(msg *Message) + func (c *Conn) SendBytes(cmd CMD, b []byte) + func (c *Conn) SendMessage(msg *Message) + func (c *Conn) SendSingle(sid string, msg *Message) + func (c *Conn) SetExtraMap(k string, v interface{}) + type DefaultLogger struct + func (d *DefaultLogger) Debug(v ...interface{}) + func (d *DefaultLogger) Debugf(format string, v ...interface{}) + func (d *DefaultLogger) Error(v ...interface{}) + func (d *DefaultLogger) Errorf(format string, v ...interface{}) + func (d *DefaultLogger) Fatal(v ...interface{}) + func (d *DefaultLogger) Fatalf(format string, v ...interface{}) + func (d *DefaultLogger) Info(v ...interface{}) + func (d *DefaultLogger) Infof(format string, v ...interface{}) + func (d *DefaultLogger) Panic(v ...interface{}) + func (d *DefaultLogger) Panicf(format string, v ...interface{}) + type DefaultProtocol struct + func NewDefaultProtocol() *DefaultProtocol + func (p *DefaultProtocol) Pack(msg *Message) ([]byte, error) + func (p *DefaultProtocol) Unpack(reader io.Reader) (msg *Message, err error) + type JSONCodec struct + func (c *JSONCodec) Decode(data []byte, v interface{}) error + func (c *JSONCodec) Encode(v interface{}) ([]byte, error) + type Level uint8 + const DEBUG + const ERROR + const FATAL + const INFO + const PANIC + type Logger interface + Debug func(v ...interface{}) + Debugf func(format string, v ...interface{}) + Error func(v ...interface{}) + Errorf func(format string, v ...interface{}) + Fatal func(v ...interface{}) + Fatalf func(format string, v ...interface{}) + Info func(v ...interface{}) + Infof func(format string, v ...interface{}) + Panic func(v ...interface{}) + Panicf func(format string, v ...interface{}) + var Flog Logger = newLogger() + type Message struct + func NewMessage(cmd CMD, data []byte) *Message + func (m *Message) Checksum() bool + func (m *Message) GetCmd() CMD + func (m *Message) GetData() []byte + func (m *Message) GetSize() uint32 + func (m *Message) String() string + type Option func(o *Options) + func WithHeartbeat(t time.Duration) Option + func WithLogger(log Logger) Option + func WithTLS(tls *tls.Config) Option + type Options struct + type PBCodec struct + func (c *PBCodec) Decode(data []byte, v interface{}) error + func (c *PBCodec) Encode(v interface{}) ([]byte, error) + type Protocol interface + Pack func(msg *Message) ([]byte, error) + Unpack func(reader io.Reader) (*Message, error) + type Server struct + func NewServer(addr string, opts ...Option) *Server + func (s *Server) Accept(ctx context.Context, listener net.Listener) + func (s *Server) Heartbeat() + func (s *Server) OnClose(callback func(c *Conn, err error)) + func (s *Server) OnConnect(callback func(c *Conn)) + func (s *Server) OnMessage(callback func(c *Conn, msg *Message)) + func (s *Server) Start() + func (s *Server) Stop() + type Session struct + func NewSession(conn *Conn) *Session + func (s *Session) BindUserID(uid string) + func (s *Session) GetConn() *Conn + func (s *Session) GetExtraMap(key string) interface{} + func (s *Session) GetSessionID() string + func (s *Session) GetUserID() string + func (s *Session) SetConn(conn *Conn) + func (s *Session) SetExtraMap(key string, value interface{}) + func (s *Session) UpdateTime()