jl-iot/mqtt/topic.go

36 lines
876 B
Go

package mqtt
import "fmt"
const (
Topic_IotServiceState string = "/%s/%s/iotss"
Topic_IotCmd string = "/%s/%s/iotcmd"
Topic_IotQd string = "/%s/%s/iotqd"
Topic_IotCj string = "/%s/%s/iotcj"
)
var topicMap = make(map[string]string, 4)
func BuildTopics(sysCode, iotCode string) {
topicMap[Topic_IotServiceState] = fmt.Sprintf(Topic_IotServiceState, sysCode, iotCode)
topicMap[Topic_IotCmd] = fmt.Sprintf(Topic_IotCmd, sysCode, iotCode)
topicMap[Topic_IotQd] = fmt.Sprintf(Topic_IotQd, sysCode, iotCode)
topicMap[Topic_IotCj] = fmt.Sprintf(Topic_IotCj, sysCode, iotCode)
}
func GetIotServiceStateTopic() string {
return topicMap[Topic_IotServiceState]
}
func GetCmdTopic() string {
return topicMap[Topic_IotCmd]
}
func GetQdTopic() string {
return topicMap[Topic_IotQd]
}
func GetCjTopic() string {
return topicMap[Topic_IotCj]
}