uplink

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// State is the state of the uplink
	State State
	// Event
	Event string
}

type Options

type Options struct {
	// PortierURL is the URL of the portier server
	PortierURL string

	// APIToken is the API token of the portier server
	APIToken string

	// MaxReconnectInterval is the maximum time to wait between reconnects
	MaxReconnectInterval time.Duration

	// ReconnectRetries is the number of retries to reconnect to the portier server
	ReconnectRetries int64
}

type State

type State string

State is the state of the relay.

const (
	// UplinkStateDisconnected is the state when the uplink is disconnected.
	Disconnected State = "disconnected"

	// Connected is the state when the uplink is connected.
	Connected State = "connected"
)
type Uplink interface {
	// Connect connects to the portier server return recv channel to receive messages from the portier server.
	// The channels will be to be closed by the uplink when the connection to the portier server is closed.
	// The recv channel will have no buffer and it is mandatory that the Router processes messages in a non-blocking way.
	Connect() (<-chan messages.Message, error)

	// Send enqueues a message to the portier server.
	// The Uplink has only a small buffer to realize backpressure in case the uplink cannot keep up with the messages, i.e. it will block.
	// This blocking must be effectively throttling the Service.
	Send(messages.Message) error

	// Close closes the uplink, the connection to the portier server and expects the uplink to close the recv channel
	Close() error

	// Returns a recv channel to listen for events
	Events() <-chan Event
}

Uplink is the uplink interface to the portier server. It is used to send messages to the portier server and to receive messages from the portier server. Moreover, it has to handle connection loss and reconnect to the portier server.

type WebsocketUplink struct {
	// Options defines the options for the uplink
	Options Options
	// contains filtered or unexported fields
}
func NewWebsocketUplink(options Options, encoderDecoder encoder.EncoderDecoder) *WebsocketUplink

NewWebsocketUplink creates a new websocket uplink.

func (*WebsocketUplink) Close

func (u *WebsocketUplink) Close() error

Close closes the uplink, the connection to the portier server and expects the uplink to close the recv channel.

func (*WebsocketUplink) Connect

func (u *WebsocketUplink) Connect() (<-chan messages.Message, error)

Connect connects to the portier server return recv channel to receive messages from the portier server.

func (*WebsocketUplink) Events

func (u *WebsocketUplink) Events() <-chan Event

func (*WebsocketUplink) Send

func (u *WebsocketUplink) Send(message messages.Message) error

Send enqueues a message to the portier server.

Jump to

Keyboard shortcuts

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