18 lines
315 B
Go
18 lines
315 B
Go
package MqttService
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
func PinNameFromTopic(topic string) (string,error) {
|
|
topicComponents := strings.Split(topic, "/")
|
|
if len(topicComponents) >= 2 {
|
|
gpioCh := topicComponents[len(topicComponents)-2]
|
|
return gpioCh, nil
|
|
|
|
} else {
|
|
return "", errors.New("invalid topic")
|
|
}
|
|
}
|