From 443ba52ab3f49a28e8874ebcb5476e36c3defb4c Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 26 Mar 2026 20:57:22 +0100 Subject: Add `Retain` attribute to MQTTMessage This allows the sending part of the code to decide about the retain flag. The MQTT go routine will set it accordingly. --- mqtt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mqtt.go') diff --git a/mqtt.go b/mqtt.go index fd1cba1..acd0108 100644 --- a/mqtt.go +++ b/mqtt.go @@ -27,6 +27,7 @@ var ( type MQTTMessage struct { Topic string Payload []byte + Retain bool } type Route struct { @@ -60,6 +61,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) { message := MQTTMessage{ Topic: strings.TrimPrefix(msg.Topic(), config.TopicPrefix + "/"), Payload: msg.Payload(), + Retain: msg.Retained(), } route.Destination <- message }) @@ -88,7 +90,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) { for message := range tx { topic := fmt.Sprintf("%s/%s", config.TopicPrefix, message.Topic) - client.Publish(topic, QoS1, RETAINED, message.Payload) + client.Publish(topic, QoS1, message.Retain, message.Payload) } } -- cgit v1.3