Documentation
¶
Overview ¶
Package coder provides a configurable WebSocket client. It leverages the coder/websocket library for underlying WebSocket functionality and is designed for concurrent safety.
Index ¶
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) HandshakeResponse() *http.Response
- func (c *Client) Read(ctx context.Context, v any) (gows.MessageType, []byte, error)
- func (c *Client) Reader(ctx context.Context) (gows.MessageType, io.Reader, error)
- func (c *Client) Write(ctx context.Context, typ gows.MessageType, p []byte) error
- func (c *Client) Writer(ctx context.Context, typ gows.MessageType) (io.WriteCloser, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotConnected = errors.New("websocket client is not connected") ErrAlreadyConnected = errors.New("websocket client is already connected") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thread-safe WebSocket client wrapper for coder/websocket. It allows for one concurrent reader and multiple concurrent writers.
func (*Client) Close ¶
Close gracefully closes the WebSocket connection. It's safe to call Close multiple times.
func (*Client) HandshakeResponse ¶
HandshakeResponse returns the HTTP response from the initial WebSocket handshake. It can be useful for inspecting headers, cookies, or the status code. The response is nil if the client has not connected yet.
func (*Client) Read ¶
Read reads a single message. It directly uses the underlying library's convenience method for simplicity and efficiency. IMPORTANT: Your application should have only ONE goroutine calling Read.
func (*Client) Reader ¶
Reader returns a streaming reader for the next message. This is useful for very large messages that shouldn't be loaded into memory at once. IMPORTANT: Your application should have only ONE goroutine calling Reader.
func (*Client) Write ¶
Write writes a single message. It is safe for concurrent use by multiple goroutines.
func (*Client) Writer ¶
func (c *Client) Writer(ctx context.Context, typ gows.MessageType) (io.WriteCloser, error)
Writer returns a streaming writer for a new message.