diff options
Diffstat (limited to 'mqtt/client.go')
| -rw-r--r-- | mqtt/client.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/mqtt/client.go b/mqtt/client.go index c3746b5..eff4736 100644 --- a/mqtt/client.go +++ b/mqtt/client.go @@ -9,6 +9,8 @@ import ( "time" ) +const MQTTProtoTopic = "/2/c/" + type Client struct { server string username string @@ -108,11 +110,13 @@ func (c *Client) Handle(channel string, h HandlerFunc) { c.channelHandlers[channel] = append(c.channelHandlers[channel], h) c.client.Subscribe(topic+"/+", 0, c.handleBrokerMessage) } + func (c *Client) GetFullTopicForChannel(channel string) string { - return c.topicRoot + "/c/" + channel + return c.topicRoot + MQTTProtoTopic + channel } + func (c *Client) GetChannelFromTopic(topic string) string { - trimmed := strings.TrimPrefix(topic, c.topicRoot+"/c/") + trimmed := strings.TrimPrefix(topic, c.topicRoot+MQTTProtoTopic) sepIndex := strings.Index(trimmed, "/") if sepIndex > 0 { return trimmed[:sepIndex] |
