Documentation ¶
Index ¶
- Constants
- func RegisterEvent(event string, callback func())
- type Action
- type Callback
- type Connection
- func (conn *Connection) AddBeforeCloseHook(hooks ...func(conn *Connection))
- func (conn *Connection) Close()
- func (conn *Connection) ID() string
- func (conn *Connection) IP() string
- func (conn *Connection) Property() *structure.ConcurrentMap[string, any]
- func (conn *Connection) Push(p []byte)
- func (conn *Connection) Read(p []byte) (int, error)
- func (conn *Connection) Write(p []byte) (int, error)
- type ConnectionHandler
- type Context
- type Engine
- type HandleFunc
- type Handler
- type Network
- type Option
- type Options
- type Reactor
- type ReactorOptions
- type Router
- type ShardSubReactor
- func (shard *ShardSubReactor) GetConnection(fd int) *Connection
- func (shard *ShardSubReactor) Offer(fds ...int)
- func (shard *ShardSubReactor) Polling(stopCh <-chan struct{}, callback func(int))
- func (shard *ShardSubReactor) RegisterConnection(conn *Connection)
- func (shard *ShardSubReactor) UnregisterConnection(conn *Connection)
- type SingleSubReactor
- func (sub *SingleSubReactor) GetConnection(fd int) *Connection
- func (sub *SingleSubReactor) Offer(fds ...int)
- func (sub *SingleSubReactor) Polling(stopCh <-chan struct{}, callback func(int))
- func (sub *SingleSubReactor) RegisterConnection(conn *Connection)
- func (sub *SingleSubReactor) UnregisterConnection(conn *Connection)
- type SubReactor
- type Thread
- type ThreadOptions
Constants ¶
const ( BeforeServerStart = "beforeServerStart" AfterServerStart = "afterServerStart" BeforeServerShutdown = "beforeServerShutdown" AfterServerShutdown = "afterServerShutdown" )
const ( ContentTypeJson = "json" ContentTypeProto = "protobuf" )
Variables ¶
This section is empty.
Functions ¶
func RegisterEvent ¶ added in v0.1.7
func RegisterEvent(event string, callback func())
RegisterEvent registers an event handler
Types ¶
type Callback ¶
type Callback struct {
// contains filtered or unexported fields
}
Callback manage connection callback handlers.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents client connection
func NewConnection ¶
func NewConnection(conn net.Conn, fd int) *Connection
NewConnection returns a new Connection instance
func (*Connection) AddBeforeCloseHook ¶
func (conn *Connection) AddBeforeCloseHook(hooks ...func(conn *Connection))
AddBeforeCloseHook adds a hook to the connection before closed
func (*Connection) IP ¶ added in v0.1.4
func (conn *Connection) IP() string
func (*Connection) Property ¶
func (conn *Connection) Property() *structure.ConcurrentMap[string, any]
Property return properties container
func (*Connection) Push ¶
func (conn *Connection) Push(p []byte)
Push send message to the connection
type ConnectionHandler ¶
type ConnectionHandler func(conn *Connection)
ConnectionHandler represents a connection handler
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine provide context/handler management
func (*Engine) Use ¶
func (e *Engine) Use(handlers ...HandleFunc)
type HandleFunc ¶
type HandleFunc func(ctx *Context)
HandleFunc represents a handler function for Context
type Handler ¶
Handler is a handler for operation
func StandardHandler ¶
StandardHandler is a function to convert standard handler.
type Network ¶ added in v0.1.7
type Network struct {
// contains filtered or unexported fields
}
Network socket server master
func (*Network) ListenWebsocket ¶ added in v0.1.7
ListenWebsocket listens for websocket connections
type Options ¶
type Options struct { // Debug enables debug logging Debug bool // OnOpen is a callback function that is called when the connection is established OnOpen ConnectionHandler // OnClose is a callback function that is called when the connection is closed OnClose ConnectionHandler // OnError is a callback function that is called when process error OnError func(ctx *Context, err error) // Middlewares is a lot of callback functions that are called when the connection send new message Middlewares []HandleFunc Reactor ReactorOptions Thread ThreadOptions Acceptor acceptor.Options }
Options represents app options
func (*Options) NewCallback ¶ added in v0.1.6
func (*Options) NewReactorOrDie ¶ added in v0.1.4
type Reactor ¶
type Reactor struct {
// contains filtered or unexported fields
}
Reactor represents the epoll model for listen connections.
func NewReactor ¶ added in v0.1.4
func NewReactor(options ReactorOptions) (reactor *Reactor, err error)
NewReactor return a new main reactor instance
func (*Reactor) Run ¶
func (reactor *Reactor) Run(stopCh <-chan struct{}, onRequest ConnectionHandler)
Run runs the Reactor with the given signal.
type ReactorOptions ¶
type ReactorOptions struct { // EpollBufferSize is the size of the active connections in every duration,default is 100 EpollBufferSize int // ThreadQueueCapacity is the cap of the thread queue, default is 100 ThreadQueueCapacity int // SubReactorShardCount is the number of sub-reactor shards, default is 32 // if the parameter is zero, the number of sub-reactor will be 1 SubReactorShardCount int }
ReactorOptions represents the options for the reactor
func (ReactorOptions) NewSubReactor ¶ added in v0.1.5
func (options ReactorOptions) NewSubReactor() SubReactor
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router represents router instance
func (*Router) OnNotFound ¶
func (router *Router) OnNotFound(handler HandleFunc) *Router
OnNotFound is called when operation is not found
type ShardSubReactor ¶
type ShardSubReactor struct {
// contains filtered or unexported fields
}
func NewShardSubReactor ¶
func NewShardSubReactor(shardCount, bufferSize int) *ShardSubReactor
func (*ShardSubReactor) GetConnection ¶
func (shard *ShardSubReactor) GetConnection(fd int) *Connection
func (*ShardSubReactor) Offer ¶
func (shard *ShardSubReactor) Offer(fds ...int)
func (*ShardSubReactor) Polling ¶
func (shard *ShardSubReactor) Polling(stopCh <-chan struct{}, callback func(int))
func (*ShardSubReactor) RegisterConnection ¶
func (shard *ShardSubReactor) RegisterConnection(conn *Connection)
func (*ShardSubReactor) UnregisterConnection ¶
func (shard *ShardSubReactor) UnregisterConnection(conn *Connection)
type SingleSubReactor ¶ added in v0.1.3
type SingleSubReactor struct {
// contains filtered or unexported fields
}
SingleSubReactor represents sub reactor
func NewSingleSubReactor ¶ added in v0.1.3
func NewSingleSubReactor(bufferSize int) *SingleSubReactor
NewSingleSubReactor creates an instance of a SingleSubReactor
func (*SingleSubReactor) GetConnection ¶ added in v0.1.3
func (sub *SingleSubReactor) GetConnection(fd int) *Connection
GetConnection returns a connection by fd
func (*SingleSubReactor) Offer ¶ added in v0.1.3
func (sub *SingleSubReactor) Offer(fds ...int)
Offer push the active connections fd to the queue
func (*SingleSubReactor) Polling ¶ added in v0.1.3
func (sub *SingleSubReactor) Polling(stopCh <-chan struct{}, callback func(int))
Polling poll with callback function
func (*SingleSubReactor) RegisterConnection ¶ added in v0.1.3
func (sub *SingleSubReactor) RegisterConnection(conn *Connection)
RegisterConnection registers a new connection to the epoll listener
func (*SingleSubReactor) UnregisterConnection ¶ added in v0.1.3
func (sub *SingleSubReactor) UnregisterConnection(conn *Connection)
UnregisterConnection removes the connection from the epoll listener
type SubReactor ¶
type SubReactor interface { RegisterConnection(conn *Connection) UnregisterConnection(conn *Connection) GetConnection(fd int) *Connection Offer(fds ...int) Polling(stopCh <-chan struct{}, callback func(int)) }
type Thread ¶ added in v0.1.3
type Thread struct {
// contains filtered or unexported fields
}
Thread represents context manager
func NewThread ¶ added in v0.1.3
func NewThread(options ThreadOptions) *Thread
NewThread returns a new Thread instance
func (*Thread) HandleRequest ¶ added in v0.1.3
func (thread *Thread) HandleRequest(conn *Connection)
HandleRequest handle new request for connection
func (*Thread) Use ¶ added in v0.1.3
func (thread *Thread) Use(handlers ...HandleFunc)
Use registers middleware
type ThreadOptions ¶ added in v0.1.3
type ThreadOptions struct { // MaxReadBufferSize is the size of the max read buffer, default is 512 MaxReadBufferSize int ContentType string WorkerPool *pool.Options // contains filtered or unexported fields }
func (ThreadOptions) NewCodec ¶ added in v0.1.5
func (options ThreadOptions) NewCodec() (cc codec.Codec)
func (ThreadOptions) NewWorkerPool ¶ added in v0.1.6
func (options ThreadOptions) NewWorkerPool() pool.GoroutinePool