Documentation
¶
Index ¶
- Constants
- Variables
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) Connect(ctx context.Context) error
- func (c *Connection) Hostname() string
- func (c *Connection) Ping(ctx context.Context) error
- func (c *Connection) Ready() <-chan struct{}
- func (c *Connection) Send(ctx context.Context, msg string) error
- func (c *Connection) SendBinary(ctx context.Context, data []byte) error
- func (c *Connection) SetOnMessage(onMessage func(context.Context, []byte, bool))
- type Mockreader
- type Mockreader_Expecter
- type Mockreader_Read_Call
- type Options
Constants ¶
const (
DefaultMaxMessageSize = 1024 * 1024
)
Variables ¶
var ErrConnectionClosed = errors.New("connection closed")
Functions ¶
This section is empty.
Types ¶
type Connection ¶ added in v0.2.0
type Connection struct {
// contains filtered or unexported fields
}
func New ¶ added in v0.6.0
func New(wsURL string, opts *Options) (*Connection, error)
New initializes a new WebSocket connection configuration with specified URL and options. It takes wsURL, a string representing the WebSocket URL, and opts, a pointer to Options with custom settings. It returns a pointer to a Connection and possible error if the URL is empty, poorly formatted, or headers are invalid.
func (*Connection) Close ¶ added in v0.2.0
func (c *Connection) Close() error
Close shuts down an established WebSocket connection gracefully. It returns an error if the connection is not yet established. The function ensures a normal closure status is sent to the WebSocket server.
func (*Connection) Connect ¶ added in v0.6.0
func (c *Connection) Connect(ctx context.Context) error
Connect establishes a WebSocket connection using the specified context. It returns an error if the onMessage callback is not set, the connection attempt fails, or if a connection is already established. The method locks the connection during setup to ensure thread safety and sets a default read limit on the WebSocket.
func (*Connection) Hostname ¶ added in v0.3.0
func (c *Connection) Hostname() string
Hostname retrieves the host name part of the URL stored in the Connection struct. It returns a string representing the host name.
func (*Connection) Ping ¶ added in v0.7.3
func (c *Connection) Ping(ctx context.Context) error
Ping sends a ping frame to the WebSocket server to check the connection's liveness. It takes ctx of type context.Context as a parameter. It returns an error if the context is canceled or if there is a failure sending the ping
func (*Connection) Ready ¶ added in v0.6.0
func (c *Connection) Ready() <-chan struct{}
Ready returns a channel that is closed when the WebSocket connection is established.
func (*Connection) Send ¶ added in v0.2.0
func (c *Connection) Send(ctx context.Context, msg string) error
Send transmits a message over an established WebSocket connection within a given context. It takes ctx of type context.Context and msg of type string as parameters. It returns an error if the context is canceled or if there is a failure writing to the WebSocket. The function waits for the connection to be ready before sending the message.
func (*Connection) SendBinary ¶ added in v0.10.0
func (c *Connection) SendBinary(ctx context.Context, data []byte) error
SendBinary transmits binary data over an established WebSocket connection within a given context. It takes ctx of type context.Context and data of type []byte as parameters. It returns an error if the context is canceled or if there is a failure writing to the WebSocket.
func (*Connection) SetOnMessage ¶ added in v0.6.0
func (c *Connection) SetOnMessage(onMessage func(context.Context, []byte, bool))
SetOnMessage sets the callback function to handle incoming messages on the connection. It takes onMessage, a function with parameters context.Context, a byte slice [] and bool flag as input. The method does not return any value and is thread-safe, locking access to the callback function.
type Mockreader ¶ added in v0.6.0
Mockreader is an autogenerated mock type for the reader type
func NewMockreader ¶ added in v0.6.0
func NewMockreader(t interface {
mock.TestingT
Cleanup(func())
}) *Mockreader
NewMockreader creates a new instance of Mockreader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*Mockreader) EXPECT ¶ added in v0.6.0
func (_m *Mockreader) EXPECT() *Mockreader_Expecter
type Mockreader_Expecter ¶ added in v0.6.0
type Mockreader_Expecter struct {
// contains filtered or unexported fields
}
func (*Mockreader_Expecter) Read ¶ added in v0.6.0
func (_e *Mockreader_Expecter) Read(p interface{}) *Mockreader_Read_Call
Read is a helper method to define mock.On call
- p []byte
type Mockreader_Read_Call ¶ added in v0.6.0
Mockreader_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read'
func (*Mockreader_Read_Call) Return ¶ added in v0.6.0
func (_c *Mockreader_Read_Call) Return(n int, err error) *Mockreader_Read_Call
func (*Mockreader_Read_Call) Run ¶ added in v0.6.0
func (_c *Mockreader_Read_Call) Run(run func(p []byte)) *Mockreader_Read_Call
func (*Mockreader_Read_Call) RunAndReturn ¶ added in v0.6.0
func (_c *Mockreader_Read_Call) RunAndReturn(run func([]byte) (int, error)) *Mockreader_Read_Call