Files
open-im-server/internal/push/offlinepush/jpush/body/platform.go
T

100 lines
1.9 KiB
Go
Raw Normal View History

2023-07-04 11:15:20 +08:00
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2023-06-30 09:45:02 +08:00
package body
2023-06-29 22:35:31 +08:00
import (
2024-04-19 22:23:08 +08:00
"github.com/openimsdk/tools/errs"
2023-07-03 14:12:29 +08:00
2024-04-19 22:23:08 +08:00
"github.com/openimsdk/protocol/constant"
2023-06-29 22:35:31 +08:00
)
const (
ANDROID = "android"
IOS = "ios"
QUICKAPP = "quickapp"
WINDOWSPHONE = "winphone"
ALL = "all"
)
type Platform struct {
Os any
2023-06-29 22:35:31 +08:00
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:
2024-04-19 22:23:08 +08:00
return errs.New("platform is all")
2023-06-29 22:35:31 +08:00
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:
2024-04-19 22:23:08 +08:00
return errs.New("unknow platform")
2023-06-29 22:35:31 +08:00
}
return nil
}
2023-06-29 22:35:31 +08:00
func (p *Platform) SetPlatform(platform string) error {
switch platform {
case constant.AndroidPlatformStr:
return p.SetAndroid()
case constant.IOSPlatformStr:
return p.SetIOS()
default:
2024-04-19 22:23:08 +08:00
return errs.New("platform err")
2023-06-29 22:35:31 +08:00
}
}
2023-06-29 22:35:31 +08:00
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
}