ws

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WSMessageBufferSize = 100
	HeaderPartsNumber   = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection added in v0.2.0

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

func NewWS

func NewWS(wsURL string, opts Options) (*Connection, error)

NewWS creates a new WebSocket connection to the specified URL with the given options. It returns a Connection object and an error if any occurred.

func (*Connection) Close added in v0.2.0

func (wsInsp *Connection) Close()

Close closes the WebSocket connection. If the connection is already closed, it returns immediately.

func (*Connection) Hostname added in v0.3.0

func (wsInsp *Connection) Hostname() string

Hostname returns the hostname of the WebSocket server.

func (*Connection) Messages added in v0.2.0

func (wsInsp *Connection) Messages() <-chan Message

Messages returns a channel that receives messages from the WebSocket connection.

func (*Connection) Send added in v0.2.0

func (wsInsp *Connection) Send(msg string) (*Message, error)

Send sends a message to the websocket connection and returns a Message and an error. It takes a string message as input and returns a pointer to a Message struct and an error. The Message struct contains the message type and data.

type ConnectionHandler added in v0.3.1

type ConnectionHandler interface {
	Messages() <-chan Message
	Hostname() string
	Send(msg string) (*Message, error)
	Close()
}

type Message

type Message struct {
	Data string      `json:"data"`
	Type MessageType `json:"type"`
}

type MessageType

type MessageType uint8
const (
	NotDefined MessageType = iota
	Request
	Response
)

func (MessageType) String added in v0.2.0

func (mt MessageType) String() string

type Options added in v0.2.0

type Options struct {
	Headers             []string
	SkipSSLVerification bool
}

Jump to

Keyboard shortcuts

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