client

package
v0.0.0-...-311d1fd Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextMessage   = websocket.TextMessage
	BinaryMessage = websocket.BinaryMessage
)

Expose message types as defined in underlying websocket library

View Source
const (
	AuthorizationHeader = "Authorization"
)
View Source
const (
	DefaultConnectionTimeout time.Duration = 60 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthInfo

type AuthInfo struct {
	SharedKey []byte
	Username  string
	Password  string
}

type Client

type Client struct {
	ConnectionFactory
	RequireAck bool
	Timeout    time.Duration
	AuthInfo   AuthInfo
	Hostname   string
	// contains filtered or unexported fields
}

func New

func New(opts ConnectionOptions) *Client

func (*Client) Connect

func (c *Client) Connect() error

Connect initializes the Session and Connection objects by opening a client connect to the target configured in the ConnectionFactory

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect terminates a client connection

func (*Client) Handshake

func (c *Client) Handshake() error

Handshake initiates handshake mode. Users must call this before attempting to send any messages when the server is configured with a shared key, otherwise the server will reject any message events. Successful completion of the handshake puts the connection into message (or forward) mode, at which time the client is free to send event messages.

func (*Client) Reconnect

func (c *Client) Reconnect() error

func (*Client) Send

func (c *Client) Send(e protocol.ChunkEncoder) error

Send sends a single protocol.ChunkEncoder across the wire. If the session is not yet in transport phase, an error is returned, and no message is sent.

func (*Client) SendCompressed

func (c *Client) SendCompressed(tag string, entries protocol.EntryList) error

func (*Client) SendCompressedFromBytes

func (c *Client) SendCompressedFromBytes(tag string, entries []byte) error

func (*Client) SendForward

func (c *Client) SendForward(tag string, entries protocol.EntryList) error

func (*Client) SendMessage

func (c *Client) SendMessage(tag string, record interface{}) error

func (*Client) SendMessageExt

func (c *Client) SendMessageExt(tag string, record interface{}) error

func (*Client) SendPacked

func (c *Client) SendPacked(tag string, entries protocol.EntryList) error

func (*Client) SendPackedFromBytes

func (c *Client) SendPackedFromBytes(tag string, entries []byte) error

func (*Client) SendRaw

func (c *Client) SendRaw(m []byte) error

SendRaw sends bytes across the wire. If the session is not yet in transport phase, an error is returned, and no message is sent.

func (*Client) TransportPhase

func (c *Client) TransportPhase() bool

TransportPhase indicates if the client has completed the initial connection handshake.

type ConnFactory

type ConnFactory struct {
	// Network indicates the type of connection. The default value is "tcp".
	Network   string
	Address   string
	TLSConfig *tls.Config
	Timeout   time.Duration
}

ConnFactory is a light wrapper for net.Dial and tls.Dial. When TLSConfig is not nil, tls.Dial is called. Otherwise, net.Dial is used. See Go's net.Dial documentation for more information.

func (*ConnFactory) New

func (f *ConnFactory) New() (net.Conn, error)

type ConnectionFactory

type ConnectionFactory interface {
	New() (net.Conn, error)
}

ConnectionFactory implementations create new connections

type ConnectionOptions

type ConnectionOptions struct {
	Factory           ConnectionFactory
	RequireAck        bool
	ConnectionTimeout time.Duration
	// TODO:
	// ReadTimeout       time.Duration
	// WriteTimeout      time.Duration
	AuthInfo AuthInfo
}

type DefaultWSConnectionFactory

type DefaultWSConnectionFactory struct {
	URL       string
	AuthInfo  *IAMAuthInfo
	TLSConfig *tls.Config
}

DefaultWSConnectionFactory is used by the client if no other ConnectionFactory is provided.

func (*DefaultWSConnectionFactory) New

func (wcf *DefaultWSConnectionFactory) New() (ext.Conn, error)

func (*DefaultWSConnectionFactory) NewSession

func (wcf *DefaultWSConnectionFactory) NewSession(connection ws.Connection) *WSSession

type IAMAuthInfo

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

func NewIAMAuthInfo

func NewIAMAuthInfo(token string) *IAMAuthInfo

func (*IAMAuthInfo) IAMToken

func (ai *IAMAuthInfo) IAMToken() string

IAMToken returns the current token value. It is thread safe.

func (*IAMAuthInfo) SetIAMToken

func (ai *IAMAuthInfo) SetIAMToken(token string)

SetIAMToken updates the token returned by IAMToken(). It is thread safe.

type MessageClient

type MessageClient interface {
	Connect() error
	Disconnect() (err error)
	Reconnect() error
	Send(e protocol.ChunkEncoder) error
	SendCompressed(tag string, entries protocol.EntryList) error
	SendCompressedFromBytes(tag string, entries []byte) error
	SendForward(tag string, entries protocol.EntryList) error
	SendMessage(tag string, record interface{}) error
	SendMessageExt(tag string, record interface{}) error
	SendPacked(tag string, entries protocol.EntryList) error
	SendPackedFromBytes(tag string, entries []byte) error
	SendRaw(raw []byte) error
}

MessageClient implementations send MessagePack messages to a peer

type Session

type Session struct {
	Connection     net.Conn
	TransportPhase bool
}

type WSClient

type WSClient struct {
	ConnectionFactory WSConnectionFactory
	ConnectionOptions ws.ConnectionOptions
	// contains filtered or unexported fields
}

WSClient manages the lifetime of a single websocket connection.

func NewWS

func NewWS(opts WSConnectionOptions) *WSClient

func (*WSClient) Connect

func (c *WSClient) Connect() error

Connect initializes the Session and Connection objects by opening a websocket connection. If AuthInfo is not nil, the token it returns will be passed via the "Authentication" header during the initial HTTP call.

func (*WSClient) Disconnect

func (c *WSClient) Disconnect() (err error)

Disconnect ends the current Session and terminates its websocket connection.

func (*WSClient) Reconnect

func (c *WSClient) Reconnect() (err error)

Reconnect terminates the existing Session and creates a new one.

func (*WSClient) Send

func (c *WSClient) Send(e protocol.ChunkEncoder) error

Send sends a single msgp.Encodable across the wire.

func (*WSClient) SendRaw

func (c *WSClient) SendRaw(m []byte) error

SendRaw sends an array of bytes across the wire.

func (*WSClient) Session

func (c *WSClient) Session() *WSSession

Session provides the web socket session instance

type WSConnectionFactory

type WSConnectionFactory interface {
	New() (ext.Conn, error)
	NewSession(ws.Connection) *WSSession
}

type WSConnectionOptions

type WSConnectionOptions struct {
	ws.ConnectionOptions
	Factory WSConnectionFactory
}

type WSSession

type WSSession struct {
	URL        string
	Connection ws.Connection
}

WSSession represents a single websocket connection.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.
ws
ext
ext/extfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
wsfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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