2022-02-03 09:03:37 +00:00
|
|
|
package status
|
|
|
|
|
2022-11-09 06:05:09 +00:00
|
|
|
import (
|
|
|
|
"github.com/appleboy/gorush/core"
|
|
|
|
)
|
2022-02-03 09:03:37 +00:00
|
|
|
|
|
|
|
type StateStorage struct {
|
2022-11-09 06:05:09 +00:00
|
|
|
store core.Storage
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 06:05:09 +00:00
|
|
|
func NewStateStorage(store core.Storage) *StateStorage {
|
2022-02-03 09:03:37 +00:00
|
|
|
return &StateStorage{
|
|
|
|
store: store,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StateStorage) Init() error {
|
|
|
|
return s.store.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StateStorage) Close() error {
|
|
|
|
return s.store.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset Client storage.
|
|
|
|
func (s *StateStorage) Reset() {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Set(core.TotalCountKey, 0)
|
|
|
|
s.store.Set(core.IosSuccessKey, 0)
|
|
|
|
s.store.Set(core.IosErrorKey, 0)
|
|
|
|
s.store.Set(core.AndroidSuccessKey, 0)
|
|
|
|
s.store.Set(core.AndroidErrorKey, 0)
|
|
|
|
s.store.Set(core.HuaweiSuccessKey, 0)
|
|
|
|
s.store.Set(core.HuaweiErrorKey, 0)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddTotalCount record push notification count.
|
|
|
|
func (s *StateStorage) AddTotalCount(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.TotalCountKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddIosSuccess record counts of success iOS push notification.
|
|
|
|
func (s *StateStorage) AddIosSuccess(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.IosSuccessKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddIosError record counts of error iOS push notification.
|
|
|
|
func (s *StateStorage) AddIosError(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.IosErrorKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddAndroidSuccess record counts of success Android push notification.
|
|
|
|
func (s *StateStorage) AddAndroidSuccess(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.AndroidSuccessKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddAndroidError record counts of error Android push notification.
|
|
|
|
func (s *StateStorage) AddAndroidError(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.AndroidErrorKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddHuaweiSuccess record counts of success Huawei push notification.
|
|
|
|
func (s *StateStorage) AddHuaweiSuccess(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.HuaweiSuccessKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddHuaweiError record counts of error Huawei push notification.
|
|
|
|
func (s *StateStorage) AddHuaweiError(count int64) {
|
2022-11-09 06:05:09 +00:00
|
|
|
s.store.Add(core.HuaweiErrorKey, count)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTotalCount show counts of all notification.
|
|
|
|
func (s *StateStorage) GetTotalCount() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.TotalCountKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetIosSuccess show success counts of iOS notification.
|
|
|
|
func (s *StateStorage) GetIosSuccess() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.IosSuccessKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetIosError show error counts of iOS notification.
|
|
|
|
func (s *StateStorage) GetIosError() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.IosErrorKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAndroidSuccess show success counts of Android notification.
|
|
|
|
func (s *StateStorage) GetAndroidSuccess() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.AndroidSuccessKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAndroidError show error counts of Android notification.
|
|
|
|
func (s *StateStorage) GetAndroidError() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.AndroidErrorKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetHuaweiSuccess show success counts of Huawei notification.
|
|
|
|
func (s *StateStorage) GetHuaweiSuccess() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.HuaweiSuccessKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetHuaweiError show error counts of Huawei notification.
|
|
|
|
func (s *StateStorage) GetHuaweiError() int64 {
|
2022-11-09 06:05:09 +00:00
|
|
|
return s.store.Get(core.HuaweiErrorKey)
|
2022-02-03 09:03:37 +00:00
|
|
|
}
|