Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrServerClosed = errors.New("server closed")
ErrServerClosed will throw when server closed
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface { // Encode will encode data before write to client Encode([]byte) []byte // Decode will decode receive data from client Decode(buf buffer.Buffer) []byte }
Codec will Decode receive data from client and Encode send data before write to client
type Connection ¶
type Handler ¶
type Handler interface { // OnConnected will call when client connected // the result action can control server OnConnected(conn Connection) (Action, error) // OnDisconnected will call when client disconnected OnDisconnected(conn Connection) error // OnReceived will call when read data from client // If Codec is config, decode data(frame) will be input when frame not nil // the result action can control server OnReceived(frame []byte, conn Connection) (Action, error) // OnError will call when any error occurred // the result action can control server OnError(conn Connection, err error) Action }
Handler is handler of client read or write data The Action of method returned can control server or connection When Action is StopServerAction: the server will stop When Action is DisconnectionAction: the connection will be close
type NothingCodec ¶
type NothingCodec struct { }
func (*NothingCodec) Encode ¶
func (n *NothingCodec) Encode(b []byte) []byte
type Option ¶
type Option func(options *Options)
func WithLogger ¶
WithLogger is edit Options Logger field
type Options ¶
type Options struct { // Logger is Logger implements Logger logger.Logger // Task is Task implements function // This function will call when server started Task Task // Codec is Codec implements // All data receive and send will use Codec Encode and Decode Codec Codec }
Options defined server options
type Server ¶
type Server interface { // Bind is bind address and handler to server Bind(address *Address, handler Handler) error // Stop will stop input addresses // When addresses empty, the server will stop all bind address Stop(addresses ...*Address) error // Start is start the server and blocking. // When server all addresses stop, will throw ErrServerClosed Start() error }
Server is multi address handler server
Click to show internal directories.
Click to hide internal directories.