From e825e6820389fab7c97ae3665155401124ab8ecf Mon Sep 17 00:00:00 2001 From: Ethel Morgan Date: Wed, 24 Jun 2020 23:21:32 +0100 Subject: make Client an interface, make Message a plain struct --- api.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 api.go (limited to 'api.go') diff --git a/api.go b/api.go new file mode 100644 index 0000000..8397cb9 --- /dev/null +++ b/api.go @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2020 Ethel Morgan +// +// SPDX-License-Identifier: MIT + +// Package catbus is a convenience wrapper around MQTT for use with Catbus. +package catbus + +type ( + MessageHandler func(Client, Message) + + Message struct { + Payload string + Retention Retention + Topic string + } + + Client interface { + Connect() error + Subscribe(topic string, f MessageHandler) error + Publish(topic string, retention Retention, payload string) error + } + + // Retention is whether or not the MQTT broker should retain the message. + Retention bool +) + +const ( + Retain = Retention(true) + DontRetain = Retention(false) +) -- cgit v1.2.3