websocket

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientNotFound = &websocket.CloseError{Code: 1000, Text: "client not found"}
	ErrSendTimeout    = &websocket.CloseError{Code: 1001, Text: "send timeout"}
)

错误定义

Functions

This section is empty.

Types

type Client

type Client struct {
	ID         string          // 探针ID
	Conn       *websocket.Conn // WebSocket连接
	Send       chan []byte     // 发送消息通道
	Manager    *Manager        // 管理器引用
	LastActive time.Time       // 最后活跃时间
	// contains filtered or unexported fields
}

Client WebSocket客户端

func (*Client) ReadPump

func (c *Client) ReadPump(ctx context.Context)

ReadPump 读取客户端消息

func (*Client) WritePump

func (c *Client) WritePump()

WritePump 向客户端写入消息

type Manager

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

Manager WebSocket连接管理器

func NewManager

func NewManager(logger *zap.Logger) *Manager

NewManager 创建新的WebSocket管理器

func (*Manager) ClientCount

func (m *Manager) ClientCount() int

ClientCount 获取客户端数量

func (*Manager) GetAllClients

func (m *Manager) GetAllClients() []string

GetAllClients 获取所有客户端ID

func (*Manager) GetClient

func (m *Manager) GetClient(probeID string) (*Client, bool)

GetClient 获取客户端

func (*Manager) Register

func (m *Manager) Register(client *Client)

Register 注册客户端(公开方法)

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run 启动管理器

func (*Manager) SendToClient

func (m *Manager) SendToClient(probeID string, message []byte) error

SendToClient 发送消息给指定客户端

func (*Manager) SetMessageHandler

func (m *Manager) SetMessageHandler(handler MessageHandler)

SetMessageHandler 设置消息处理器

func (*Manager) SetPongHandler added in v0.1.7

func (m *Manager) SetPongHandler(handler PongHandler)

SetPongHandler 设置 Pong 处理器

type MessageHandler

type MessageHandler func(ctx context.Context, probeID string, messageType string, data json.RawMessage) error

MessageHandler 消息处理器接口

type PongHandler added in v0.1.7

type PongHandler func(probeID string)

PongHandler Pong 处理器接口

Jump to

Keyboard shortcuts

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