dispatcher
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package mqtt
|
||||
|
||||
import "log"
|
||||
import "strings"
|
||||
import "fmt"
|
||||
import MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||
import "github.com/google/uuid"
|
||||
@ -124,3 +125,20 @@ func StopMqttClient() {
|
||||
mqttClient.Disconnect(250)
|
||||
}
|
||||
|
||||
func TopicMatchesSubscription(topic, subscription string) bool {
|
||||
topicSegments := strings.Split(topic, "/")
|
||||
subscriptionSegments := strings.Split(subscription, "/")
|
||||
|
||||
for i, subSegment := range subscriptionSegments {
|
||||
if subSegment == "+" {
|
||||
continue
|
||||
} else if subSegment == "#" {
|
||||
return true
|
||||
} else if i < len(topicSegments) && subSegment != topicSegments[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user