From 356e502ed8b5434aa8f662bbfcb3ddd3511252ac Mon Sep 17 00:00:00 2001 From: Joel Schmid Date: Sat, 20 Mar 2021 11:31:19 +0100 Subject: [PATCH] simplified mqtt topic regex --- weathersource/mqtt-source.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/weathersource/mqtt-source.go b/weathersource/mqtt-source.go index a6bf798..5848d40 100644 --- a/weathersource/mqtt-source.go +++ b/weathersource/mqtt-source.go @@ -1,6 +1,7 @@ package weathersource import ( + "fmt" "regexp" "strconv" "strings" @@ -12,7 +13,7 @@ import ( ) var uuidRegexPattern = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" -var mqttTopicRegexPattern = "^sensor/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/(temp|pressure|humidity|co2level)$" +var mqttTopicRegexPattern = fmt.Sprintf("^sensor/%s/(temp|pressure|humidity|co2level)$", uuidRegexPattern) var regexTopic *regexp.Regexp = regexp.MustCompile(mqttTopicRegexPattern) var regexUuid *regexp.Regexp = regexp.MustCompile(uuidRegexPattern)