Documentation
¶
Overview ¶
Package server 提供连接事件处理器
Package server 提供 Gateway 服务器配置选项 ¶
Package server 提供基于 gnet 的高性能 WebSocket 服务器
Index ¶
- Constants
- type Handler
- func (h *Handler) AuthMiddleware(next protocol.HandlerFunc) protocol.HandlerFunc
- func (h *Handler) HandleDeliveryAck(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleDisconnect(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleHandshake(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleHeartbeat(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleReadReceipt(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleRecallMessage(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleSendMessage(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) HandleSync(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
- func (h *Handler) RegisterHandlers()
- type Option
- func WithAddr(addr string) Option
- func WithBucketNum(num int) Option
- func WithBufferSize(read, write int) Option
- func WithGatewayInfo(id, addr string) Option
- func WithHeartbeat(interval, timeout time.Duration) Option
- func WithHeartbeatInterval(interval time.Duration) Option
- func WithIdleTimeout(timeout time.Duration) Option
- func WithMaxConnections(max int) Option
- func WithReadBufferSize(size int) Option
- func WithTLS(certFile, keyFile string) Option
- func WithWSPath(path string) Option
- func WithWorkerPoolSize(size int) Option
- func WithWriteBufferSize(size int) Option
- type Options
- type Server
- func (s *Server) ConnManager() *connection.Manager
- func (s *Server) MessageClient() message.MessageServiceClient
- func (s *Server) OnBoot(eng gnet.Engine) gnet.Action
- func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action)
- func (s *Server) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)
- func (s *Server) OnShutdown(eng gnet.Engine)
- func (s *Server) OnTick() (delay time.Duration, action gnet.Action)
- func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action)
- func (s *Server) RedisClient() interface{}
- func (s *Server) Router() *protocol.Router
- func (s *Server) SetMessageClient(client message.MessageServiceClient)
- func (s *Server) SetRedisClient(client interface{})
- func (s *Server) Start() error
- func (s *Server) Stats() map[string]interface{}
- func (s *Server) Stop(ctx context.Context) error
Constants ¶
View Source
const ErrorCmd = 900
ErrorCmd 错误命令类型
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler 连接事件处理器
func (*Handler) AuthMiddleware ¶
func (h *Handler) AuthMiddleware(next protocol.HandlerFunc) protocol.HandlerFunc
AuthMiddleware 认证中间件
func (*Handler) HandleDeliveryAck ¶
func (h *Handler) HandleDeliveryAck(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleDeliveryAck 处理送达确认
func (*Handler) HandleDisconnect ¶
func (h *Handler) HandleDisconnect(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleDisconnect 处理断开连接请求
func (*Handler) HandleHandshake ¶
func (h *Handler) HandleHandshake(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleHandshake 处理握手请求
func (*Handler) HandleHeartbeat ¶
func (h *Handler) HandleHeartbeat(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleHeartbeat 处理心跳请求
func (*Handler) HandleReadReceipt ¶
func (h *Handler) HandleReadReceipt(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleReadReceipt 处理已读回执
func (*Handler) HandleRecallMessage ¶
func (h *Handler) HandleRecallMessage(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleRecallMessage 处理撤回消息请求
func (*Handler) HandleSendMessage ¶
func (h *Handler) HandleSendMessage(ctx context.Context, connID string, packet *protocol.Packet) (*protocol.Packet, error)
HandleSendMessage 处理发送消息请求
type Option ¶
type Option func(*Options)
Option 配置选项函数类型
func WithHeartbeat ¶
WithHeartbeat 设置心跳配置
func WithHeartbeatInterval ¶
WithHeartbeatInterval 设置心跳间隔
type Options ¶
type Options struct {
// 网络配置
Addr string // 监听地址,格式 "host:port"
MaxConnections int // 最大连接数
ReadBufferSize int // 读缓冲区大小
WriteBufferSize int // 写缓冲区大小
// WebSocket 配置
WSPath string // WebSocket 路径,默认 "/ws"
EnableWS bool // 是否启用 WebSocket
// 超时配置
ReadTimeout time.Duration // 读超时
WriteTimeout time.Duration // 写超时
IdleTimeout time.Duration // 空闲超时(心跳超时)
// 心跳配置
HeartbeatInterval time.Duration // 心跳间隔
HeartbeatTimeout time.Duration // 心跳超时(未收到心跳多久后断开)
// 连接分桶配置
BucketNum int // 连接分桶数量(减少锁竞争)
// 工作池配置
WorkerPoolSize int // 工作协程池大小
// 服务发现
GatewayID string // 网关实例ID
GatewayAddr string // 网关外部地址(用于服务发现)
// TLS 配置
EnableTLS bool // 是否启用 TLS
CertFile string // 证书文件路径
KeyFile string // 私钥文件路径
}
Options Gateway 服务器配置选项
type Server ¶
type Server struct {
gnet.BuiltinEventEngine
// contains filtered or unexported fields
}
Server Gateway 服务器
func (*Server) MessageClient ¶
func (s *Server) MessageClient() message.MessageServiceClient
MessageClient 返回 Message Service 客户端
func (*Server) SetMessageClient ¶
func (s *Server) SetMessageClient(client message.MessageServiceClient)
SetMessageClient 设置 Message Service 客户端
func (*Server) SetRedisClient ¶
func (s *Server) SetRedisClient(client interface{})
SetRedisClient 设置 Redis 客户端
Click to show internal directories.
Click to hide internal directories.