luxws

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("connection is busy")

ErrBusy is the error returned when concurrent requests for sending a message are made.

View Source
var ErrClosed = net.ErrClosed

ErrClosed is the error returned by an I/O call on a network connection that has already been closed, or that is closed by another goroutine before the I/O is completed.

View Source
var ErrIgnore = errors.New("ignore response")

ErrIgnore is the error used by response handler callbacks when a given message needs to be ignored.

View Source
var ErrNotRunning = errors.New("receiver not running")

ErrNotRunning is the error returned when the websocket receiver goroutine is no longer running and no specific error is available.

Functions

This section is empty.

Types

type LogFunc added in v0.3.0

type LogFunc func(format string, v ...any)

LogFunc describes a logging function (e.g. log.Printf).

type Option added in v0.3.0

type Option func(*transport)

Option is the type of options for transports.

func WithLogFunc added in v0.3.0

func WithLogFunc(logf LogFunc) Option

WithLogFunc supplies a logging function to the transport. Received and sent messages are written as log messages.

type ResponseHandlerFunc

type ResponseHandlerFunc func([]byte) error

ResponseHandlerFunc is the prototype for response handler callbacks.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport is a wrapper for a LuxWS websocket connection.

func Dial

func Dial(ctx context.Context, address string, opts ...Option) (*Transport, error)

Dial connects to a LuxWS server. The address must have the format "<host>:<port>" (see net.JoinHostPort). Use the context to establish a timeout.

func (Transport) Close

func (t Transport) Close() error

Close immediately closes the underlying network connection. Any blocked read or write operations will be unblocked and return errors.

func (Transport) LocalAddr

func (t Transport) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (Transport) RemoteAddr

func (t Transport) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (Transport) RoundTrip

func (t Transport) RoundTrip(ctx context.Context, req string, fn ResponseHandlerFunc) error

RoundTrip sends a request as a single message. All incoming messages are passed to the given handler function. If a response message is deemed an acceptable response the handler must return nil. If the message is not acceptable, but not an error, ErrIgnore can be returned by the handler. In all other cases an error must be returned.

Jump to

Keyboard shortcuts

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