mirror of
https://github.com/wahyd4/jpush-api-go-client.git
synced 2026-08-09 04:46:43 +10:00
66 lines
915 B
Go
66 lines
915 B
Go
package jpushclient
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
const (
|
|
IOS = "ios"
|
|
ANDROID = "android"
|
|
WINPHONE = "winphone"
|
|
)
|
|
|
|
type Platform struct {
|
|
Os interface{}
|
|
osArry []string
|
|
}
|
|
|
|
func (this *Platform) All() {
|
|
this.Os = "all"
|
|
}
|
|
|
|
func (this *Platform) Add(os string) error {
|
|
if this.Os == nil {
|
|
this.osArry = make([]string, 0, 3)
|
|
} else {
|
|
switch this.Os.(type) {
|
|
case string:
|
|
panic("platform is all")
|
|
default:
|
|
}
|
|
}
|
|
|
|
//判断是否重复
|
|
for _, value := range this.osArry {
|
|
if os == value {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
switch os {
|
|
case IOS:
|
|
fallthrough
|
|
case ANDROID:
|
|
fallthrough
|
|
case WINPHONE:
|
|
this.osArry = append(this.osArry, os)
|
|
this.Os = this.osArry
|
|
default:
|
|
return errors.New("unknow platform")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (this *Platform) AddIOS() {
|
|
this.Add(IOS)
|
|
}
|
|
|
|
func (this *Platform) AddAndrid() {
|
|
this.Add(ANDROID)
|
|
}
|
|
|
|
func (this *Platform) AddWinphone() {
|
|
this.Add(WINPHONE)
|
|
}
|