Documentation
¶
Index ¶
- Variables
- func GetUidFromContext(conn gnet.Conn) string
- func ParseProtoAddr(protoAddr string) (string, string, error)
- type ConnManager
- type Context
- func (c *Context) Body() []byte
- func (c *Context) Conn() gnet.Conn
- func (c *Context) ConnReq() *proto.Connect
- func (c *Context) Uid() string
- func (c *Context) Write(data []byte)
- func (c *Context) WriteConnack(connack *proto.Connack)
- func (c *Context) WriteErr(err error)
- func (c *Context) WriteErrorAndStatus(err error, status proto.Status)
- func (c *Context) WriteMessage(m gproto.Message)
- func (c *Context) WriteOk()
- func (c *Context) WriteStatus(status proto.Status)
- type Handler
- type Option
- func WithAddr(addr string) Option
- func WithClosePath(path string) Option
- func WithConnPath(path string) Option
- func WithLogDetailOn(on bool) Option
- func WithMaxIdle(maxIdle time.Duration) Option
- func WithMessagePoolOn(on bool) Option
- func WithMessagePoolSize(size int) Option
- func WithOnMessage(onMessage func(conn gnet.Conn, msg *proto.Message)) Option
- func WithOnRequest(onRequest func(conn gnet.Conn, req *proto.Request)) Option
- func WithOnResponse(onResponse func(conn gnet.Conn, resp *proto.Response)) Option
- func WithRequestPoolSize(size int) Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithTimingWheelSize(size int64) Option
- func WithTimingWheelTick(tick time.Duration) Option
- type Options
- type RateLimiter
- type Server
- func (s *Server) MessagePoolRunning() int
- func (s *Server) OnBoot(eng gnet.Engine) (action gnet.Action)
- func (s *Server) OnClose(conn gnet.Conn, err error) (action gnet.Action)
- func (s *Server) OnMessage(h func(conn gnet.Conn, msg *proto.Message))
- func (s *Server) OnTick() (delay time.Duration, action gnet.Action)
- func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action)
- func (s *Server) Options() *Options
- func (s *Server) Request(uid string, p string, body []byte) (*proto.Response, error)
- func (s *Server) RequestAsync(uid string, p string, body []byte) error
- func (s *Server) RequestPoolRunning() int
- func (s *Server) RequestWithContext(ctx context.Context, uid string, p string, body []byte) (*proto.Response, error)
- func (s *Server) Route(p string, h Handler)
- func (s *Server) Schedule(interval time.Duration, f func()) *timingwheel.Timer
- func (s *Server) Send(uid string, msg *proto.Message) error
- func (s *Server) Start() error
- func (s *Server) Stop()
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrConnIsNil = errors.New("conn is nil")
)
Functions ¶
func GetUidFromContext ¶
Types ¶
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func NewConnManager ¶
func NewConnManager() *ConnManager
func (*ConnManager) RemoveConn ¶
func (c *ConnManager) RemoveConn(uid string)
type Context ¶
func NewContext ¶
func (*Context) WriteConnack ¶
func (*Context) WriteErrorAndStatus ¶
func (*Context) WriteMessage ¶
func (*Context) WriteStatus ¶
type Option ¶
type Option func(*Options)
func WithClosePath ¶
func WithConnPath ¶
func WithLogDetailOn ¶
func WithMaxIdle ¶
func WithMessagePoolOn ¶
func WithMessagePoolSize ¶
func WithOnResponse ¶
func WithRequestPoolSize ¶
func WithRequestTimeout ¶
func WithTimingWheelSize ¶
func WithTimingWheelTick ¶
type Options ¶
type Options struct {
Addr string
RequestPoolSize int // The size of the request pool, the default is 10000
MessagePoolSize int // The size of the message pool, the default is 10000
MessagePoolOn bool // Whether to open the message pool, the default is true
ConnPath string
ClosePath string
RequestTimeout time.Duration
OnMessage func(conn gnet.Conn, msg *proto.Message)
MaxIdle time.Duration
TimingWheelTick time.Duration // The time-round training interval must be 1ms or more
TimingWheelSize int64 // Time wheel size
OnRequest func(conn gnet.Conn, req *proto.Request)
OnResponse func(conn gnet.Conn, resp *proto.Response)
LogDetailOn bool // 是否开启详细日志
}
func NewOptions ¶
func NewOptions() *Options
type RateLimiter ¶
RateLimiter is the struct used to keep tracking consumed memory size.
func NewRateLimiter ¶
func NewRateLimiter(max uint64) *RateLimiter
NewRateLimiter creates and returns a rate limiter instance.
func (*RateLimiter) Decrease ¶
func (r *RateLimiter) Decrease(sz uint64)
Decrease decreases the recorded in memory log size by sz bytes.
func (*RateLimiter) Enabled ¶
func (r *RateLimiter) Enabled() bool
Enabled returns a boolean flag indicating whether the rate limiter is enabled.
func (*RateLimiter) Get ¶
func (r *RateLimiter) Get() uint64
Get returns the recorded in memory log size.
func (*RateLimiter) Increase ¶
func (r *RateLimiter) Increase(sz uint64)
Increase increases the recorded in memory log size by sz bytes.
func (*RateLimiter) RateLimited ¶
func (r *RateLimiter) RateLimited() bool
RateLimited returns a boolean flag indicating whether the node is rate limited.
func (*RateLimiter) Set ¶
func (r *RateLimiter) Set(sz uint64)
Set sets the recorded in memory log size to sz bytes.
type Server ¶
type Server struct {
gnet.BuiltinEventEngine
mslog.Log
ConnManager *ConnManager
// contains filtered or unexported fields
}
func (*Server) MessagePoolRunning ¶
func (*Server) RequestAsync ¶
func (*Server) RequestPoolRunning ¶
func (*Server) RequestWithContext ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.