2016-05-02 03:04:19 +00:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
)
|
|
|
|
|
2016-05-02 09:03:08 +00:00
|
|
|
// StatusApp is app status structure
|
|
|
|
type statApp struct {
|
|
|
|
TotalCount int64 `json:"total_count"`
|
|
|
|
Ios IosStatus `json:"ios"`
|
|
|
|
Android AndroidStatus `json:"android"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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)
|
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)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|