2016-05-02 03:04:19 +00:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
)
|
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
// statApp is app status structure
|
2016-05-02 09:03:08 +00:00
|
|
|
type statApp struct {
|
|
|
|
TotalCount int64 `json:"total_count"`
|
|
|
|
Ios IosStatus `json:"ios"`
|
|
|
|
Android AndroidStatus `json:"android"`
|
2020-09-04 03:01:21 +00:00
|
|
|
Huawei HuaweiStatus `json:"huawei"`
|
2016-05-02 09:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AndroidStatus is android structure
|
|
|
|
type AndroidStatus struct {
|
|
|
|
PushSuccess int64 `json:"push_success"`
|
|
|
|
PushError int64 `json:"push_error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IosStatus is iOS structure
|
|
|
|
type IosStatus struct {
|
|
|
|
PushSuccess int64 `json:"push_success"`
|
|
|
|
PushError int64 `json:"push_error"`
|
|
|
|
}
|
|
|
|
|
2020-09-04 03:01:21 +00:00
|
|
|
// HuaweiStatus is android structure
|
|
|
|
type HuaweiStatus struct {
|
|
|
|
PushSuccess int64 `json:"push_success"`
|
|
|
|
PushError int64 `json:"push_error"`
|
|
|
|
}
|
|
|
|
|
2016-07-31 13:10:59 +00:00
|
|
|
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
2016-05-02 09:03:08 +00:00
|
|
|
func New() *Storage {
|
2016-05-02 03:04:19 +00:00
|
|
|
return &Storage{
|
2016-05-02 09:03:08 +00:00
|
|
|
stat: &statApp{},
|
2016-05-02 03:04:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// Storage is interface structure
|
2016-05-02 03:04:19 +00:00
|
|
|
type Storage struct {
|
2016-05-02 09:03:08 +00:00
|
|
|
stat *statApp
|
2016-05-02 03:04:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// Init client storage.
|
2016-05-02 11:42:21 +00:00
|
|
|
func (s *Storage) Init() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:39:24 +00:00
|
|
|
// Close the storage connection
|
|
|
|
func (s *Storage) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// Reset Client storage.
|
2016-05-02 11:42:21 +00:00
|
|
|
func (s *Storage) Reset() {
|
2016-08-03 07:02:13 +00:00
|
|
|
atomic.StoreInt64(&s.stat.TotalCount, 0)
|
|
|
|
atomic.StoreInt64(&s.stat.Ios.PushSuccess, 0)
|
|
|
|
atomic.StoreInt64(&s.stat.Ios.PushError, 0)
|
|
|
|
atomic.StoreInt64(&s.stat.Android.PushSuccess, 0)
|
|
|
|
atomic.StoreInt64(&s.stat.Android.PushError, 0)
|
2020-09-04 03:01:21 +00:00
|
|
|
atomic.StoreInt64(&s.stat.Huawei.PushSuccess, 0)
|
|
|
|
atomic.StoreInt64(&s.stat.Huawei.PushError, 0)
|
2016-05-02 11:42:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// AddTotalCount record push notification count.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) AddTotalCount(count int64) {
|
2016-05-02 03:04:19 +00:00
|
|
|
atomic.AddInt64(&s.stat.TotalCount, count)
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// AddIosSuccess record counts of success iOS push notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) AddIosSuccess(count int64) {
|
2016-05-02 03:04:19 +00:00
|
|
|
atomic.AddInt64(&s.stat.Ios.PushSuccess, count)
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// AddIosError record counts of error iOS push notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) AddIosError(count int64) {
|
2016-05-02 03:04:19 +00:00
|
|
|
atomic.AddInt64(&s.stat.Ios.PushError, count)
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// AddAndroidSuccess record counts of success Android push notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) AddAndroidSuccess(count int64) {
|
2016-05-02 03:04:19 +00:00
|
|
|
atomic.AddInt64(&s.stat.Android.PushSuccess, count)
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// AddAndroidError record counts of error Android push notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) AddAndroidError(count int64) {
|
2016-05-02 03:04:19 +00:00
|
|
|
atomic.AddInt64(&s.stat.Android.PushError, count)
|
|
|
|
}
|
|
|
|
|
2020-09-04 03:01:21 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// GetTotalCount show counts of all notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) GetTotalCount() int64 {
|
2016-05-02 03:04:19 +00:00
|
|
|
count := atomic.LoadInt64(&s.stat.TotalCount)
|
|
|
|
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// GetIosSuccess show success counts of iOS notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) GetIosSuccess() int64 {
|
2016-05-02 03:04:19 +00:00
|
|
|
count := atomic.LoadInt64(&s.stat.Ios.PushSuccess)
|
|
|
|
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// GetIosError show error counts of iOS notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) GetIosError() int64 {
|
2016-05-02 03:04:19 +00:00
|
|
|
count := atomic.LoadInt64(&s.stat.Ios.PushError)
|
|
|
|
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// GetAndroidSuccess show success counts of Android notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) GetAndroidSuccess() int64 {
|
2016-05-02 03:04:19 +00:00
|
|
|
count := atomic.LoadInt64(&s.stat.Android.PushSuccess)
|
|
|
|
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:57:00 +00:00
|
|
|
// GetAndroidError show error counts of Android notification.
|
2016-05-02 09:03:08 +00:00
|
|
|
func (s *Storage) GetAndroidError() int64 {
|
2016-05-02 03:04:19 +00:00
|
|
|
count := atomic.LoadInt64(&s.stat.Android.PushError)
|
|
|
|
|
|
|
|
return count
|
|
|
|
}
|
2020-09-04 03:01:21 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|