ws

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 14 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 {
	Conn *Conn
	// contains filtered or unexported fields
}

func Dial

func Dial(ctx context.Context, url string, logger *zap.Logger, headers ...http.Header) (*Client, error)

func NewClientFromConn

func NewClientFromConn(conn *Conn) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any) (json.RawMessage, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

func (*Client) OnNotification

func (c *Client) OnNotification(method string, handler app.NotificationHandler)

func (*Client) ReadLoop

func (c *Client) ReadLoop()

type Conn

type Conn struct {
	WS     *websocket.Conn
	Logger *zap.Logger
	// contains filtered or unexported fields
}

func NewConn

func NewConn(ws *websocket.Conn, logger *zap.Logger) *Conn

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request, logger *zap.Logger) (*Conn, error)

Upgrade 升级 HTTP 连接到 WebSocket。

func (*Conn) Close

func (c *Conn) Close() error

Close 标记 closed → 等 writeLoop 退出 → 关 underlying WS。 不直接 close(sendQueue),因为其他 goroutine 可能并发 enqueue,会 panic。

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (*jsonrpc.Request, *jsonrpc.Response, error)

func (*Conn) SendNotification

func (c *Conn) SendNotification(method string, params any) error

func (*Conn) SendResponse

func (c *Conn) SendResponse(resp *jsonrpc.Response) error

func (*Conn) WriteJSON

func (c *Conn) WriteJSON(v any) error

WriteJSON marshal v 后非阻塞 enqueue 到 sendQueue。 队列满 = 本 conn 已经病了 → 主动 Close 触发对端重连(agent 重连会触发 full sync)。 一般调用方(如 Broadcast fan-out)忽略错误。

Jump to

Keyboard shortcuts

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