You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
831 B
37 lines
831 B
package models
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type ReferenceKind string
|
|
|
|
var (
|
|
RKDeviceID ReferenceKind = "DeviceID"
|
|
RKBridgeID ReferenceKind = "BridgeID"
|
|
RKTag ReferenceKind = "Tag"
|
|
RKAll ReferenceKind = "All"
|
|
RKName ReferenceKind = "Name"
|
|
)
|
|
|
|
func ParseFetchString(fetchStr string) (ReferenceKind, string) {
|
|
if strings.HasPrefix(fetchStr, "tag:") {
|
|
return RKTag, fetchStr[4:]
|
|
} else if strings.HasPrefix(fetchStr, "bridge:") {
|
|
return RKBridgeID, fetchStr[7:]
|
|
} else if strings.HasPrefix(fetchStr, "id:") {
|
|
return RKDeviceID, fetchStr[7:]
|
|
} else if strings.HasPrefix(fetchStr, "name:") {
|
|
return RKName, fetchStr[7:]
|
|
} else if fetchStr == "all" {
|
|
return RKAll, ""
|
|
} else {
|
|
_, err := strconv.Atoi(fetchStr)
|
|
if err != nil {
|
|
return RKName, fetchStr
|
|
}
|
|
|
|
return RKDeviceID, fetchStr
|
|
}
|
|
}
|