server

package
v0.0.0-...-46ee16b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 表示一个WebSocket客户端连接

type ConnectionManager

type ConnectionManager struct {
	// contains filtered or unexported fields
}

ConnectionManager 管理所有的WebSocket连接和会话

func NewConnectionManager

func NewConnectionManager(db *gorm.DB) *ConnectionManager

NewConnectionManager 创建新的连接管理器

func (*ConnectionManager) CleanInactiveConnections

func (cm *ConnectionManager) CleanInactiveConnections(inactiveTimeout time.Duration)

CleanInactiveConnections 清理不活跃的连接

func (*ConnectionManager) GetActiveConnections

func (cm *ConnectionManager) GetActiveConnections() int

GetActiveConnections 获取活跃连接数

func (*ConnectionManager) GetClient

func (cm *ConnectionManager) GetClient(connectionID string) (*Client, bool)

GetClient 根据连接ID获取客户端

func (*ConnectionManager) GetClientByCustomerID

func (cm *ConnectionManager) GetClientByCustomerID(customerID uint) (*Client, bool)

GetClientByCustomerID 根据客户ID获取客户端

func (*ConnectionManager) HandleWebSocket

func (cm *ConnectionManager) HandleWebSocket(w http.ResponseWriter, r *http.Request, handlers MessageHandlers)

HandleWebSocket 处理WebSocket连接请求

func (*ConnectionManager) Register

func (cm *ConnectionManager) Register(client *Client)

Register 注册新的客户端连接

func (*ConnectionManager) Unregister

func (cm *ConnectionManager) Unregister(client *Client)

Unregister 注销客户端连接

type MessageHandlers

type MessageHandlers interface {
	HandleMessage(customerID uint, message []byte) ([]byte, error)
}

MessageHandlers 定义消息处理器

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

NewServer 创建新的服务器实例

func (*Server) Router

func (s *Server) Router() *gin.Engine

Router 返回gin路由实例

func (*Server) SetupRoutes

func (s *Server) SetupRoutes(db *gorm.DB, handlers MessageHandlers, cm *ConnectionManager)

SetupRoutes 配置所有路由

func (*Server) Start

func (s *Server) Start(port int) error

Start 启动HTTP服务器

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop 优雅地停止HTTP服务器

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL