Add Huawei Mobile Services Support to Gorush (#523)

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
M. Salih Karakaşlı
2020-09-04 06:01:21 +03:00
committed by GitHub
parent 3db8b4f006
commit 3918fab908
23 changed files with 829 additions and 14 deletions

View File

@@ -59,6 +59,8 @@ func (s *Storage) Reset() {
s.setBadger(storage.IosErrorKey, 0)
s.setBadger(storage.AndroidSuccessKey, 0)
s.setBadger(storage.AndroidErrorKey, 0)
s.setBadger(storage.HuaweiSuccessKey, 0)
s.setBadger(storage.HuaweiErrorKey, 0)
}
func (s *Storage) setBadger(key string, count int64) {
@@ -129,6 +131,18 @@ func (s *Storage) AddAndroidError(count int64) {
s.setBadger(storage.AndroidErrorKey, total)
}
// AddHuaweiSuccess record counts of success Huawei push notification.
func (s *Storage) AddHuaweiSuccess(count int64) {
total := s.GetHuaweiSuccess() + count
s.setBadger(storage.HuaweiSuccessKey, total)
}
// AddHuaweiError record counts of error Huawei push notification.
func (s *Storage) AddHuaweiError(count int64) {
total := s.GetHuaweiError() + count
s.setBadger(storage.HuaweiErrorKey, total)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
@@ -168,3 +182,19 @@ func (s *Storage) GetAndroidError() int64 {
return count
}
// GetHuaweiSuccess show success counts of Huawei notification.
func (s *Storage) GetHuaweiSuccess() int64 {
var count int64
s.getBadger(storage.HuaweiSuccessKey, &count)
return count
}
// GetHuaweiError show error counts of Huawei notification.
func (s *Storage) GetHuaweiError() int64 {
var count int64
s.getBadger(storage.HuaweiErrorKey, &count)
return count
}

View File

@@ -45,6 +45,8 @@ func (s *Storage) Reset() {
s.setBoltDB(storage.IosErrorKey, 0)
s.setBoltDB(storage.AndroidSuccessKey, 0)
s.setBoltDB(storage.AndroidErrorKey, 0)
s.setBoltDB(storage.HuaweiSuccessKey, 0)
s.setBoltDB(storage.HuaweiErrorKey, 0)
}
func (s *Storage) setBoltDB(key string, count int64) {
@@ -91,6 +93,18 @@ func (s *Storage) AddAndroidError(count int64) {
s.setBoltDB(storage.AndroidErrorKey, total)
}
// AddHuaweiSuccess record counts of success Huawei push notification.
func (s *Storage) AddHuaweiSuccess(count int64) {
total := s.GetHuaweiSuccess() + count
s.setBoltDB(storage.HuaweiSuccessKey, total)
}
// AddHuaweiError record counts of error Huawei push notification.
func (s *Storage) AddHuaweiError(count int64) {
total := s.GetHuaweiError() + count
s.setBoltDB(storage.HuaweiErrorKey, total)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
@@ -130,3 +144,19 @@ func (s *Storage) GetAndroidError() int64 {
return count
}
// GetHuaweiSuccess show success counts of Huawei notification.
func (s *Storage) GetHuaweiSuccess() int64 {
var count int64
s.getBoltDB(storage.HuaweiSuccessKey, &count)
return count
}
// GetHuaweiError show error counts of Huawei notification.
func (s *Storage) GetHuaweiError() int64 {
var count int64
s.getBoltDB(storage.HuaweiErrorKey, &count)
return count
}

View File

@@ -47,6 +47,8 @@ func (s *Storage) Reset() {
s.setBuntDB(storage.IosErrorKey, 0)
s.setBuntDB(storage.AndroidSuccessKey, 0)
s.setBuntDB(storage.AndroidErrorKey, 0)
s.setBuntDB(storage.HuaweiSuccessKey, 0)
s.setBuntDB(storage.HuaweiErrorKey, 0)
}
func (s *Storage) setBuntDB(key string, count int64) {
@@ -104,6 +106,18 @@ func (s *Storage) AddAndroidError(count int64) {
s.setBuntDB(storage.AndroidErrorKey, total)
}
// AddHuaweiSuccess record counts of success Huawei push notification.
func (s *Storage) AddHuaweiSuccess(count int64) {
total := s.GetHuaweiSuccess() + count
s.setBuntDB(storage.HuaweiSuccessKey, total)
}
// AddHuaweiError record counts of error Huawei push notification.
func (s *Storage) AddHuaweiError(count int64) {
total := s.GetHuaweiError() + count
s.setBuntDB(storage.HuaweiErrorKey, total)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
@@ -143,3 +157,19 @@ func (s *Storage) GetAndroidError() int64 {
return count
}
// GetHuaweiSuccess show success counts of Huawei notification.
func (s *Storage) GetHuaweiSuccess() int64 {
var count int64
s.getBuntDB(storage.HuaweiSuccessKey, &count)
return count
}
// GetHuaweiError show error counts of Huawei notification.
func (s *Storage) GetHuaweiError() int64 {
var count int64
s.getBuntDB(storage.HuaweiErrorKey, &count)
return count
}

View File

@@ -56,6 +56,8 @@ func (s *Storage) Reset() {
s.setLevelDB(storage.IosErrorKey, 0)
s.setLevelDB(storage.AndroidSuccessKey, 0)
s.setLevelDB(storage.AndroidErrorKey, 0)
s.setLevelDB(storage.HuaweiSuccessKey, 0)
s.setLevelDB(storage.HuaweiErrorKey, 0)
}
// AddTotalCount record push notification count.
@@ -88,6 +90,18 @@ func (s *Storage) AddAndroidError(count int64) {
s.setLevelDB(storage.AndroidErrorKey, total)
}
// AddHuaweiSuccess record counts of success Huawei push notification.
func (s *Storage) AddHuaweiSuccess(count int64) {
total := s.GetHuaweiSuccess() + count
s.setLevelDB(storage.HuaweiSuccessKey, total)
}
// AddHuaweiError record counts of error Huawei push notification.
func (s *Storage) AddHuaweiError(count int64) {
total := s.GetHuaweiError() + count
s.setLevelDB(storage.HuaweiErrorKey, total)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
@@ -127,3 +141,19 @@ func (s *Storage) GetAndroidError() int64 {
return count
}
// GetHuaweiSuccess show success counts of Huawei notification.
func (s *Storage) GetHuaweiSuccess() int64 {
var count int64
s.getLevelDB(storage.HuaweiSuccessKey, &count)
return count
}
// GetHuaweiError show error counts of Huawei notification.
func (s *Storage) GetHuaweiError() int64 {
var count int64
s.getLevelDB(storage.HuaweiErrorKey, &count)
return count
}

View File

@@ -9,6 +9,7 @@ type statApp struct {
TotalCount int64 `json:"total_count"`
Ios IosStatus `json:"ios"`
Android AndroidStatus `json:"android"`
Huawei HuaweiStatus `json:"huawei"`
}
// AndroidStatus is android structure
@@ -23,6 +24,12 @@ type IosStatus struct {
PushError int64 `json:"push_error"`
}
// HuaweiStatus is android structure
type HuaweiStatus struct {
PushSuccess int64 `json:"push_success"`
PushError int64 `json:"push_error"`
}
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
func New() *Storage {
return &Storage{
@@ -52,6 +59,8 @@ func (s *Storage) Reset() {
atomic.StoreInt64(&s.stat.Ios.PushError, 0)
atomic.StoreInt64(&s.stat.Android.PushSuccess, 0)
atomic.StoreInt64(&s.stat.Android.PushError, 0)
atomic.StoreInt64(&s.stat.Huawei.PushSuccess, 0)
atomic.StoreInt64(&s.stat.Huawei.PushError, 0)
}
// AddTotalCount record push notification count.
@@ -79,6 +88,16 @@ func (s *Storage) AddAndroidError(count int64) {
atomic.AddInt64(&s.stat.Android.PushError, count)
}
// AddHuaweiSuccess record counts of success Huawei push notification.
func (s *Storage) AddHuaweiSuccess(count int64) {
atomic.AddInt64(&s.stat.Huawei.PushSuccess, count)
}
// AddHuaweiError record counts of error Huawei push notification.
func (s *Storage) AddHuaweiError(count int64) {
atomic.AddInt64(&s.stat.Huawei.PushError, count)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
count := atomic.LoadInt64(&s.stat.TotalCount)
@@ -113,3 +132,17 @@ func (s *Storage) GetAndroidError() int64 {
return count
}
// GetHuaweiSuccess show success counts of Huawei notification.
func (s *Storage) GetHuaweiSuccess() int64 {
count := atomic.LoadInt64(&s.stat.Huawei.PushSuccess)
return count
}
// GetHuaweiError show error counts of Huawei notification.
func (s *Storage) GetHuaweiError() int64 {
count := atomic.LoadInt64(&s.stat.Huawei.PushError)
return count
}

View File

@@ -55,6 +55,8 @@ func (s *Storage) Reset() {
s.client.Set(storage.IosErrorKey, int64(0), 0)
s.client.Set(storage.AndroidSuccessKey, int64(0), 0)
s.client.Set(storage.AndroidErrorKey, int64(0), 0)
s.client.Set(storage.HuaweiSuccessKey, int64(0), 0)
s.client.Set(storage.HuaweiErrorKey, int64(0), 0)
}
// AddTotalCount record push notification count.
@@ -82,6 +84,16 @@ func (s *Storage) AddAndroidError(count int64) {
s.client.IncrBy(storage.AndroidErrorKey, count)
}
// AddHuaweiSuccess record counts of success Android push notification.
func (s *Storage) AddHuaweiSuccess(count int64) {
s.client.IncrBy(storage.HuaweiSuccessKey, count)
}
// AddHuaweiError record counts of error Android push notification.
func (s *Storage) AddHuaweiError(count int64) {
s.client.IncrBy(storage.HuaweiErrorKey, count)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
@@ -121,3 +133,19 @@ func (s *Storage) GetAndroidError() int64 {
return count
}
// GetHuaweiSuccess show success counts of Huawei notification.
func (s *Storage) GetHuaweiSuccess() int64 {
var count int64
s.getInt64(storage.HuaweiSuccessKey, &count)
return count
}
// GetHuaweiError show error counts of Huawei notification.
func (s *Storage) GetHuaweiError() int64 {
var count int64
s.getInt64(storage.HuaweiErrorKey, &count)
return count
}

View File

@@ -15,6 +15,12 @@ const (
// AndroidErrorKey is key name for android error count of storage
AndroidErrorKey = "gorush-android-error-count"
// HuaweiSuccessKey is key name for huawei success count of storage
HuaweiSuccessKey = "gorush-huawei-success-count"
// HuaweiErrorKey is key name for huawei error count of storage
HuaweiErrorKey = "gorush-huawei-error-count"
)
// Storage interface
@@ -26,10 +32,14 @@ type Storage interface {
AddIosError(int64)
AddAndroidSuccess(int64)
AddAndroidError(int64)
AddHuaweiSuccess(int64)
AddHuaweiError(int64)
GetTotalCount() int64
GetIosSuccess() int64
GetIosError() int64
GetAndroidSuccess() int64
GetAndroidError() int64
GetHuaweiSuccess() int64
GetHuaweiError() int64
Close() error
}