client

package
v0.0.0-...-c164061 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 6 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 {
	*Options
	// contains filtered or unexported fields
}

Client is a structure representing a client in a WebSocket communication setup. It contains options for configuration, channels for errors and messages, handlers for errors and messages, a map for managing active connections, and a Mutex for safe concurrent access.

func New

func New(opt *Options) *Client

New creates a new Client with the given options. It sets up channels for errors and messages, default handlers for errors and messages, and a map for active WebSocket connections.

func (*Client) Connect

func (cl *Client) Connect(ctx context.Context, u string)

Connect establishes a WebSocket connection to the given URL. It adds the new connection to the client's map of connections and starts listening on it.

func (*Client) HandleErrorFunc

func (cl *Client) HandleErrorFunc(fn func(error))

HandleErrorFunc sets the function to be called when an error occurs. The function should take an error as its argument.

func (*Client) HandleMessageFunc

func (cl *Client) HandleMessageFunc(fn func(message.Message))

HandleMessageFunc sets the function to be called when a message is received. The function should take a message as its argument.

func (*Client) Listen

func (cl *Client) Listen(ctx context.Context) error

Listen starts listening for errors and messages on the client's channels. When a message or an error is received, it calls the appropriate handler function in a new goroutine. The function returns when the provided context is done.

func (*Client) SendMessage

func (cl *Client) SendMessage(ctx context.Context, msg message.Message)

SendMessage sends the given message to all active WebSocket connections of the client. It first marshals the message into a byte slice. If an error occurs, it sends the error on the error channel.

type Options

type Options struct {
	ReadLimit int64
}

Options represents the configuration options for a Client. It currently only includes a read limit for WebSocket connections.

Jump to

Keyboard shortcuts

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