transport

package
v0.4.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	TxResponseErr int = -1
	TxResponseOK  int = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventHandlerFunc

type EventHandlerFunc func(e TransporterEvent)

type HTTP

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

HTTP is a Transporter that sends and receives data and control messages by sending HTTP requests to a URL.

func NewHTTPTransport

func NewHTTPTransport(
	clientID string,
	server string,
	tlsConfig *tls.Config,
	userAgent string,
	pollingInterval time.Duration,
) (*HTTP, error)

func (*HTTP) Connect

func (t *HTTP) Connect() error

func (*HTTP) Disconnect

func (t *HTTP) Disconnect(quiesce uint)

func (*HTTP) ReloadTLSConfig

func (t *HTTP) ReloadTLSConfig(tlsConfig *tls.Config) error

ReloadTLSConfig creates a new HTTP client with the provided TLS config.

func (*HTTP) SetEventHandler

func (t *HTTP) SetEventHandler(f EventHandlerFunc) error

func (*HTTP) SetRxHandler

func (t *HTTP) SetRxHandler(f RxHandlerFunc) error

func (*HTTP) Tx

func (t *HTTP) Tx(
	addr string,
	metadata map[string]string,
	data []byte,
) (responseCode int, responseMetadata map[string]string, responseData []byte, err error)

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Body       json.RawMessage
	Metadata   map[string]string
}

HTTPResponse is a data structure representing an HTTP response received from an HTTP request sent through the transport.

type MQTT

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

MQTT is a Transporter that sends and receives data and control messages over MQTT by subscribing and publishing to topics on an MQTT broker.

func NewMQTTTransport

func NewMQTTTransport(clientID string, brokers []string, tlsConfig *tls.Config) (*MQTT, error)

NewMQTTTransport creates a transport suitable for transmitting data over a set of MQTT topics.

func (*MQTT) Connect

func (t *MQTT) Connect() error

Connect connects an MQTT client to the configured broker and waits for the connection to open.

func (*MQTT) Disconnect

func (t *MQTT) Disconnect(quiesce uint)

Disconnect closes the connection to the MQTT broker, waiting for the specified number of milliseconds for work to complete.

func (*MQTT) ReloadTLSConfig

func (t *MQTT) ReloadTLSConfig(tlsConfig *tls.Config) error

ReloadTLSConfig creates a new MQTT client with the given TLS config, disconnects the previous client, and connects the new one.

func (*MQTT) SetEventHandler

func (t *MQTT) SetEventHandler(f EventHandlerFunc) error

func (*MQTT) SetRxHandler

func (t *MQTT) SetRxHandler(f RxHandlerFunc) error

SetRxHandler stores a reference to f, which is then called whenever data is received over the inbound data topic.

func (*MQTT) Tx

func (t *MQTT) Tx(
	addr string,
	metadata map[string]string,
	data []byte,
) (responseCode int, responseMetadata map[string]string, responseData []byte, err error)

Tx publishes data to an MQTT topic created by combining client information with addr.

type Noop

type Noop struct{}

Noop is a Transporter that does nothing. This Transport is used to enable a "local only" dispatch mode.

func NewNoopTransport

func NewNoopTransport() (*Noop, error)

func (*Noop) Connect

func (t *Noop) Connect() error

func (*Noop) Disconnect

func (t *Noop) Disconnect(quiesce uint)

func (*Noop) ReloadTLSConfig

func (t *Noop) ReloadTLSConfig(tlsConfig *tls.Config) error

func (*Noop) SetEventHandler

func (t *Noop) SetEventHandler(f EventHandlerFunc) error

func (*Noop) SetRxHandler

func (t *Noop) SetRxHandler(f RxHandlerFunc) error

func (*Noop) Tx

func (t *Noop) Tx(
	addr string,
	metadata map[string]string,
	data []byte,
) (responseCode int, responseMetadata map[string]string, responseData []byte, err error)

type RxHandlerFunc

type RxHandlerFunc func(addr string, metadata map[string]interface{}, data []byte) error

type Transporter

type Transporter interface {
	// Connect begins listening over specific network connections and receiving
	// data.
	Connect() error

	// Disconnect disconnects the transport, performing any graceful shutdown
	// necessary.
	Disconnect(quiesce uint)

	// Tx sends a message to the given address, using metadata and data
	// according to the specific nature of the transport.Transporter
	// implementation.
	Tx(
		addr string,
		metadata map[string]string,
		data []byte,
	) (responseCode int, responseMetadata map[string]string, responseData []byte, err error)

	// SetRxHandler stores a reference to f, which is then called whenever data
	// is received over the network.
	SetRxHandler(f RxHandlerFunc) error

	// ReloadTLSConfig forces the transport to replace its TLS configuration
	// with tlsConfig.
	ReloadTLSConfig(tlsConfig *tls.Config) error

	// SetEventHandler stores a reference to f, which is then called whenever an
	// event occurs in the transporter.
	SetEventHandler(f EventHandlerFunc) error
}

Transporter is an interface representing the ability to send and receive data. It abstracts away the concrete implementation, leaving that up to the implementing type.

type TransporterEvent

type TransporterEvent uint
const (
	TransporterEventConnected    TransporterEvent = 0
	TransporterEventDisconnected TransporterEvent = 1
)

Jump to

Keyboard shortcuts

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