Files
new-server/models/shared.go
T
2021-09-28 21:54:03 +02:00

38 lines
831 B
Go

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
}
}