Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) BindNotificationContext(ctx context.Context)
- func (c *Client) Call(ctx context.Context, method string, params any) (json.RawMessage, error)
- func (c *Client) Close() error
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Notify(method string, params any) error
- func (c *Client) OnNotification(method string, handler app.NotificationHandler)
- func (c *Client) OnNotificationInline(method string, handler app.NotificationHandler)
- func (c *Client) ReadLoop()
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) ReadMessage() (*jsonrpc.Request, *jsonrpc.Response, error)
- func (c *Conn) SendNotification(method string, params any) error
- func (c *Conn) SendResponse(resp *jsonrpc.Response) error
- func (c *Conn) WriteJSON(v any) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // SendQueueSize / WriteDeadline 可在 master 启动时用 settings 覆盖(spec §5.2)。 SendQueueSize = 1024 WriteDeadline = 10 * time.Second )
View Source
var ErrConnClosed = errors.New("ws: connection closed")
ErrConnClosed 表示 ws 连接已关闭,所有在飞 Call 被就地终止。
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Conn *Conn
// CallTimeout 是单次 Call 的默认超时;<=0 关闭。装配代码可覆盖。
CallTimeout time.Duration
// contains filtered or unexported fields
}
func Dial ¶
func Dial(ctx context.Context, url string, logger *zap.Logger, headers ...http.Header) (*Client, error)
Dial 用默认 dialer 拨号(行为与历史一致)。
func DialWithDialer ¶ added in v0.0.7
func DialWithDialer(ctx context.Context, dialer *websocket.Dialer, url string, logger *zap.Logger, headers ...http.Header) (*Client, error)
DialWithDialer 用调用方提供的 dialer 拨号,便于注入 unix NetDialContext。
func NewClientFromConn ¶
func (*Client) BindNotificationContext ¶ added in v0.0.13
BindNotificationContext binds future notification handlers to the owning server lifecycle. The context is also cancelled when this connection exits.
func (*Client) OnNotification ¶
func (c *Client) OnNotification(method string, handler app.NotificationHandler)
func (*Client) OnNotificationInline ¶ added in v0.0.13
func (c *Client) OnNotificationInline(method string, handler app.NotificationHandler)
OnNotificationInline registers a bounded, non-blocking handler that runs on the reader goroutine. Other notification handlers retain asynchronous dispatch.
type Conn ¶
type Conn struct {
WS *websocket.Conn
Logger *zap.Logger
// contains filtered or unexported fields
}
func (*Conn) Close ¶
Close 标记 closed → 等 writeLoop 退出 → 关 underlying WS。 不直接 close(sendQueue),因为其他 goroutine 可能并发 enqueue,会 panic。
func (*Conn) ReadMessage ¶
func (*Conn) SendNotification ¶
SendNotification 发送单向通知——可丢消息。队列满时丢弃本条并告警,不关连接: 通知都有兜底(full-sync/心跳周期重发),丢一条的代价远小于整条连接重连风暴。
Click to show internal directories.
Click to hide internal directories.