From c99fe43dfc12cda96896b07b9469f581489abfb0 Mon Sep 17 00:00:00 2001 From: Alek Kim Date: Thu, 19 Nov 2026 15:04:44 +0900 Subject: [PATCH] add MQTT topic helper functions for operation and deployment --- mqtt.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 mqtt.go diff --git a/mqtt.go b/mqtt.go new file mode 100644 index 0000000..8f92169 --- /dev/null +++ b/mqtt.go @@ -0,0 +1,33 @@ +package model + +const ( + topicOperation = "op" + topicDeployment = "deployment" +) + +// QOS is the predefined Quality of Service level for MQTT messages. +// +//goland:noinspection GoUnusedConst +const QOS = 2 + +// OperationTopic returns the topic for operation messages for a given client ID. +// +//goland:noinspection GoUnusedExportedFunction +func OperationTopic(clientId string) string { + return makeTopic(clientId, topicOperation) +} + +// DeploymentTopic returns the topic for deployment messages for a given client ID. +// +//goland:noinspection GoUnusedExportedFunction +func DeploymentTopic(clientId string) string { + return makeTopic(clientId, topicDeployment) +} + +func makeTopic(clientId, topic string) string { + if clientId != "" { + clientId += "/" + } + + return clientId + topic +}