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

4 years ago
4 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. type ReferenceKind string
  7. var (
  8. RKDeviceID ReferenceKind = "DeviceID"
  9. RKBridgeID ReferenceKind = "BridgeID"
  10. RKTag ReferenceKind = "Tag"
  11. RKAll ReferenceKind = "All"
  12. RKName ReferenceKind = "Name"
  13. )
  14. func ParseFetchString(fetchStr string) (ReferenceKind, string) {
  15. if strings.HasPrefix(fetchStr, "tag:") {
  16. return RKTag, fetchStr[4:]
  17. } else if strings.HasPrefix(fetchStr, "bridge:") {
  18. return RKBridgeID, fetchStr[7:]
  19. } else if strings.HasPrefix(fetchStr, "id:") {
  20. return RKDeviceID, fetchStr[7:]
  21. } else if strings.HasPrefix(fetchStr, "name:") {
  22. return RKName, fetchStr[7:]
  23. } else if fetchStr == "all" {
  24. return RKAll, ""
  25. } else {
  26. _, err := strconv.Atoi(fetchStr)
  27. if err != nil {
  28. return RKName, fetchStr
  29. }
  30. return RKDeviceID, fetchStr
  31. }
  32. }