brands.go 679 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package model
  2. import "strings"
  3. const (
  4. _brandOhters = 0
  5. _brandXiaomi = 1
  6. _brandHuawei = 2
  7. _brandOppo = 3
  8. _brandVivo = 4
  9. _brandMeizu = 5
  10. _brandSamsung = 6
  11. )
  12. // mapping 映射可以解决一个品牌对应多个品牌标识的问题
  13. var brandMapping = map[string]int{
  14. "xiaomi": _brandXiaomi,
  15. "huawei": _brandHuawei,
  16. "honor": _brandHuawei,
  17. "oppo": _brandOppo,
  18. "vivo": _brandVivo,
  19. "meizu": _brandMeizu,
  20. "samsung": _brandSamsung,
  21. }
  22. // DeviceBrand .
  23. func DeviceBrand(s string) int {
  24. s = strings.Trim(s, " ")
  25. if s == "" {
  26. return _brandOhters
  27. }
  28. s = strings.ToLower(s)
  29. if v, ok := brandMapping[s]; ok {
  30. return v
  31. }
  32. return _brandOhters
  33. }