platform.go 927 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package jpushclient
  2. import (
  3. "errors"
  4. )
  5. const (
  6. IOS = "ios"
  7. ANDROID = "android"
  8. WINPHONE = "winphone"
  9. )
  10. type Platform struct {
  11. Os interface{}
  12. osArry []string
  13. }
  14. func (this *Platform) All() {
  15. this.Os = "all"
  16. }
  17. func (this *Platform) Add(os string) error {
  18. if this.Os == nil {
  19. this.osArry = make([]string, 0, 3)
  20. } else {
  21. switch this.Os.(type) {
  22. case string:
  23. return errors.New("platform is all")
  24. default:
  25. }
  26. }
  27. //判断是否重复
  28. for _, value := range this.osArry {
  29. if os == value {
  30. return nil
  31. }
  32. }
  33. switch os {
  34. case IOS:
  35. fallthrough
  36. case ANDROID:
  37. fallthrough
  38. case WINPHONE:
  39. this.osArry = append(this.osArry, os)
  40. this.Os = this.osArry
  41. default:
  42. return errors.New("unknow platform")
  43. }
  44. return nil
  45. }
  46. func (this *Platform) AddIOS() {
  47. this.Add(IOS)
  48. }
  49. func (this *Platform) AddAndrid() {
  50. this.Add(ANDROID)
  51. }
  52. func (this *Platform) AddWinphone() {
  53. this.Add(WINPHONE)
  54. }