Documentation ¶
Index ¶
- Constants
- Variables
- func SetLogger(l Logger)
- type CMD
- type Codec
- type Conn
- 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
- 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
- type JSONCodec
- type Level
- type Logger
- type Message
- type Option
- type Options
- type PBCodec
- type Protocol
- type 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
- 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()
Constants ¶
const (
// IdleTime If no data is sent to the server within 60 seconds, the connection will be forcibly closed
IdleTime = 60
)
Variables ¶
var ( // ErrServerClosed occurs when heartbeat detection the connection is not active ErrServerClosed = errors.New("server closed idle connection") // ErrClientClosed occurs when client close the connection ErrClientClosed = errors.New("client closed") )
Functions ¶
Types ¶
type Conn ¶
Conn defines parameters for accept an client
func (*Conn) GetExtraMap ¶
GetExtraMap get the extra data
func (*Conn) GetRawConn ¶
GetRawConn get the raw net.Conn from the client connection
func (*Conn) SendMessage ¶
SendMessage send message into channel
func (*Conn) SendSingle ¶
SendSingle send message to single
func (*Conn) SetExtraMap ¶
SetExtraMap set the extra data
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
func (*DefaultLogger) Debug ¶
func (d *DefaultLogger) Debug(v ...interface{})
Debug logs a message at level Debug on the standard logger
func (*DefaultLogger) Debugf ¶
func (d *DefaultLogger) Debugf(format string, v ...interface{})
Debugf logs a message at level Debug on the standard logger
func (*DefaultLogger) Error ¶
func (d *DefaultLogger) Error(v ...interface{})
Error logs a message at level Error on the standard logger
func (*DefaultLogger) Errorf ¶
func (d *DefaultLogger) Errorf(format string, v ...interface{})
Errorf logs a message at level Error on the standard logger
func (*DefaultLogger) Fatal ¶
func (d *DefaultLogger) Fatal(v ...interface{})
Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1
func (*DefaultLogger) Fatalf ¶
func (d *DefaultLogger) Fatalf(format string, v ...interface{})
Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1
func (*DefaultLogger) Info ¶
func (d *DefaultLogger) Info(v ...interface{})
Info logs a message at level Info on the standard logger
func (*DefaultLogger) Infof ¶
func (d *DefaultLogger) Infof(format string, v ...interface{})
Infof logs a message at level Info on the standard logger
func (*DefaultLogger) Panic ¶
func (d *DefaultLogger) Panic(v ...interface{})
Panic logs a message at level Panic on the standard logger
func (*DefaultLogger) Panicf ¶
func (d *DefaultLogger) Panicf(format string, v ...interface{})
Panicf logs a message at level Panic on the standard logger
type DefaultProtocol ¶
type DefaultProtocol struct{}
DefaultProtocol is the default packet ╔═══════════╤════════╤═════════╗ ║ FIELD │ TYPE │ SIZE ║ ╠═══════════╪════════╪═════════╣ ║ Cmd │ uint16 │ 2 ║ ║ Size │ uint32 │ 4 ║ ║ Checksum │ uint32 │ 4 ║ ║ Data │ []byte │ dynamic ║ ╚═══════════╧════════╧═════════╝
func NewDefaultProtocol ¶
func NewDefaultProtocol() *DefaultProtocol
NewDefaultProtocol create a *DefaultPacker with initial field value.
type JSONCodec ¶
type JSONCodec struct{}
JSONCodec implements the Codec interface
type Logger ¶
type Logger interface { Info(v ...interface{}) Infof(format string, v ...interface{}) Debug(v ...interface{}) Debugf(format string, v ...interface{}) Error(v ...interface{}) Errorf(format string, v ...interface{}) Fatal(v ...interface{}) Fatalf(format string, v ...interface{}) Panic(v ...interface{}) Panicf(format string, v ...interface{}) }
var Flog Logger = newLogger()
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server defines parameters for running an TCP network
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session struct
func (*Session) BindUserID ¶
BindUserID bind a user ID to session
func (*Session) GetExtraMap ¶
GetExtraMap get the extra data
func (*Session) GetSessionID ¶
GetSessionID get a session ID
func (*Session) SetExtraMap ¶
SetExtraMap set the extra data