useragent.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) [2022] [巴拉迪维 BaratSemet]
  2. // [ohUrlShortener] is licensed under Mulan PSL v2.
  3. // You can use this software according to the terms and conditions of the Mulan PSL v2.
  4. // You may obtain a copy of Mulan PSL v2 at:
  5. // http://license.coscl.org.cn/MulanPSL2
  6. // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  7. // See the Mulan PSL v2 for more details.
  8. package utils
  9. import (
  10. "regexp"
  11. )
  12. func IsAndroid(ua string) bool {
  13. regex := regexp.MustCompile(`(?i)Android\/[\d.]+`)
  14. return regex.MatchString(ua)
  15. }
  16. func IsIPhone(ua string) bool {
  17. regex := regexp.MustCompile(`(?i)iPhone\/[\d.]+`)
  18. return regex.MatchString(ua)
  19. }
  20. func IsIPad(ua string) bool {
  21. regex := regexp.MustCompile(`(?i)iPad\/[\d.]+`)
  22. return regex.MatchString(ua)
  23. }
  24. func IsWeChatUA(ua string) bool {
  25. regex := regexp.MustCompile(`(?i)MicroMessenger\/[\d.]+`)
  26. return regex.MatchString(ua)
  27. }
  28. func IsDingTalk(ua string) bool {
  29. regex := regexp.MustCompile(`(?i)DingTalk\/[\d.]+`)
  30. return regex.MatchString(ua)
  31. }
  32. func IsSafari(ua string) bool {
  33. regex := regexp.MustCompile(`(?i)Version\/[\d.]+ Safari\/[\d.]+`)
  34. return regex.MatchString(ua)
  35. }
  36. func IsChrome(ua string) bool {
  37. regex := regexp.MustCompile(`(?i)Chrome\/[\d.]+ Safari`)
  38. return regex.MatchString(ua)
  39. }
  40. func IsFirefox(ua string) bool {
  41. regex := regexp.MustCompile(`(?i)Firefox\/[\d.]+`)
  42. return regex.MatchString(ua)
  43. }