代码拉取完成,页面将自动刷新
package push
import "gitee.com/alonGroup/jpushgo/common"
type Platform struct {
value []string
}
func NewPlatform() *Platform {
return &Platform{}
}
// 如果有 "all",只会返回字符串 "all"
// 其他情况都是 []string{},包含具体的平台参数
func (p *Platform) Value() interface{} {
if p.has(ALL) {
return ALL
}
return p.value
}
func (p *Platform) All() {
p.value = []string{ALL}
}
// 添加 platform,可选传参: "all", "ios", "android", "winphone"
func (p *Platform) Add(platforms ...string) error {
if len(platforms) == 0 {
return nil
}
if p.value == nil {
p.value = make([]string, 0)
}
// 去重
platforms = common.UniqString(platforms)
for _, platform := range platforms {
if !isValidPlatform(platform) {
return common.ErrInvalidPlatform
}
// 不要重复添加,如果有 set 就方便了
if !p.has(platform) {
p.value = append(p.value, platform)
}
}
return nil
}
func (p *Platform) has(platform string) bool {
if p.value == nil {
return false
}
for _, v := range p.value {
if v == ALL || v == platform {
return true
}
}
return false
}
func isValidPlatform(platform string) bool {
switch platform {
case ALL, PLATFORM_IOS, PLATFORM_ANDROID, PLATFORM_WP:
return true
}
return false
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。