gateway

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package gateway provides a pico-cs MQTT broker gateway.

Index

Constants

View Source
const (
	DefaultTopicRoot = "pico-cs"
	DefaultHost      = "localhost"
	DefaultPort      = "1883"
)

Default values.

View Source
const DefChanSize = 100

DefChanSize defines the default channel size.

Variables

This section is empty.

Functions

func CheckLevelName

func CheckLevelName(name string) error

CheckLevelName checks if topic level name consists of valid characters.

Types

type Config

type Config struct {
	// root part of all gateway MQTT topics
	TopicRoot string
	// MQTT broker host
	Host string
	// MQTT broker port
	Port string
	// MQTT authentication username
	Username string
	// MQTT authentication password
	Password string
}

Config represents mqtt configuration data for the gateway.

type Gateway

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

Gateway represents a MQTT broker gateway.

func New

func New(lg logger.Logger, config *Config) (*Gateway, error)

New returns a new gateway instance.

func (*Gateway) Close

func (gw *Gateway) Close() error

Close closes the gateway.

func (*Gateway) Listen

func (gw *Gateway) Listen() error

Listen starts the gateway listening to the mqtt broker.

func (*Gateway) Publish

func (gw *Gateway) Publish(topicStrs []string, retain bool, value any)

Publish publishes a message.

func (*Gateway) PublishErr

func (gw *Gateway) PublishErr(topicStrs []string, retain bool, err error)

PublishErr publishes a error message

func (*Gateway) Subscribe

func (gw *Gateway) Subscribe(hndCh chan<- *HndMsg, owner any, topicStrs []string, fn HndFn)

Subscribe subscribes a message handler.

func (*Gateway) Unsubscribe

func (gw *Gateway) Unsubscribe(owner any, topicStrs []string)

Unsubscribe unsubscribes a message handler.

type HndFn

type HndFn func(payload any) (any, error)

HndFn represents a handler function.

type HndMsg

type HndMsg struct {
	TopicStrs []string
	Fn        HndFn
	Value     any
}

HndMsg represents a message provided to a registered handler.

Jump to

Keyboard shortcuts

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