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.
84 lines
1.3 KiB
84 lines
1.3 KiB
2 years ago
|
package body
|
||
3 years ago
|
|
||
|
import (
|
||
2 years ago
|
"OpenIM/pkg/common/constant"
|
||
3 years ago
|
"errors"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
ANDROID = "android"
|
||
|
IOS = "ios"
|
||
|
QUICKAPP = "quickapp"
|
||
|
WINDOWSPHONE = "winphone"
|
||
|
ALL = "all"
|
||
|
)
|
||
|
|
||
|
type Platform struct {
|
||
|
Os interface{}
|
||
|
osArry []string
|
||
|
}
|
||
|
|
||
|
func (p *Platform) Set(os string) error {
|
||
|
if p.Os == nil {
|
||
|
p.osArry = make([]string, 0, 4)
|
||
|
} else {
|
||
|
switch p.Os.(type) {
|
||
|
case string:
|
||
|
return errors.New("platform is all")
|
||
|
default:
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for _, value := range p.osArry {
|
||
|
if os == value {
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
switch os {
|
||
|
case IOS:
|
||
|
fallthrough
|
||
|
case ANDROID:
|
||
|
fallthrough
|
||
|
case QUICKAPP:
|
||
|
fallthrough
|
||
|
case WINDOWSPHONE:
|
||
|
p.osArry = append(p.osArry, os)
|
||
|
p.Os = p.osArry
|
||
|
default:
|
||
|
return errors.New("unknow platform")
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
func (p *Platform) SetPlatform(platform string) error {
|
||
|
switch platform {
|
||
3 years ago
|
case constant.AndroidPlatformStr:
|
||
3 years ago
|
return p.SetAndroid()
|
||
3 years ago
|
case constant.IOSPlatformStr:
|
||
3 years ago
|
return p.SetIOS()
|
||
|
default:
|
||
|
return errors.New("platform err")
|
||
|
}
|
||
|
|
||
|
}
|
||
|
func (p *Platform) SetIOS() error {
|
||
|
return p.Set(IOS)
|
||
|
}
|
||
|
|
||
|
func (p *Platform) SetAndroid() error {
|
||
|
return p.Set(ANDROID)
|
||
|
}
|
||
|
|
||
|
func (p *Platform) SetQuickApp() error {
|
||
|
return p.Set(QUICKAPP)
|
||
|
}
|
||
|
|
||
|
func (p *Platform) SetWindowsPhone() error {
|
||
|
return p.Set(WINDOWSPHONE)
|
||
|
}
|
||
|
|
||
|
func (p *Platform) SetAll() {
|
||
|
p.Os = ALL
|
||
|
}
|