refactor(storage): move interface to core package
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/appleboy/gorush/config"
|
||||
"github.com/appleboy/gorush/core"
|
||||
"github.com/appleboy/gorush/logx"
|
||||
"github.com/appleboy/gorush/storage"
|
||||
"github.com/appleboy/gorush/storage/badger"
|
||||
"github.com/appleboy/gorush/storage/boltdb"
|
||||
"github.com/appleboy/gorush/storage/buntdb"
|
||||
@@ -57,7 +57,7 @@ type HuaweiStatus struct {
|
||||
func InitAppStatus(conf *config.ConfYaml) error {
|
||||
logx.LogAccess.Info("Init App Status Engine as ", conf.Stat.Engine)
|
||||
|
||||
var store storage.Storage
|
||||
var store core.Storage
|
||||
switch conf.Stat.Engine {
|
||||
case "memory":
|
||||
store = memory.New()
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package status
|
||||
|
||||
import "github.com/appleboy/gorush/storage"
|
||||
import (
|
||||
"github.com/appleboy/gorush/core"
|
||||
)
|
||||
|
||||
type StateStorage struct {
|
||||
store storage.Storage
|
||||
store core.Storage
|
||||
}
|
||||
|
||||
func NewStateStorage(store storage.Storage) *StateStorage {
|
||||
func NewStateStorage(store core.Storage) *StateStorage {
|
||||
return &StateStorage{
|
||||
store: store,
|
||||
}
|
||||
@@ -22,81 +24,81 @@ func (s *StateStorage) Close() error {
|
||||
|
||||
// Reset Client storage.
|
||||
func (s *StateStorage) Reset() {
|
||||
s.store.Set(storage.TotalCountKey, 0)
|
||||
s.store.Set(storage.IosSuccessKey, 0)
|
||||
s.store.Set(storage.IosErrorKey, 0)
|
||||
s.store.Set(storage.AndroidSuccessKey, 0)
|
||||
s.store.Set(storage.AndroidErrorKey, 0)
|
||||
s.store.Set(storage.HuaweiSuccessKey, 0)
|
||||
s.store.Set(storage.HuaweiErrorKey, 0)
|
||||
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)
|
||||
}
|
||||
|
||||
// AddTotalCount record push notification count.
|
||||
func (s *StateStorage) AddTotalCount(count int64) {
|
||||
s.store.Add(storage.TotalCountKey, count)
|
||||
s.store.Add(core.TotalCountKey, count)
|
||||
}
|
||||
|
||||
// AddIosSuccess record counts of success iOS push notification.
|
||||
func (s *StateStorage) AddIosSuccess(count int64) {
|
||||
s.store.Add(storage.IosSuccessKey, count)
|
||||
s.store.Add(core.IosSuccessKey, count)
|
||||
}
|
||||
|
||||
// AddIosError record counts of error iOS push notification.
|
||||
func (s *StateStorage) AddIosError(count int64) {
|
||||
s.store.Add(storage.IosErrorKey, count)
|
||||
s.store.Add(core.IosErrorKey, count)
|
||||
}
|
||||
|
||||
// AddAndroidSuccess record counts of success Android push notification.
|
||||
func (s *StateStorage) AddAndroidSuccess(count int64) {
|
||||
s.store.Add(storage.AndroidSuccessKey, count)
|
||||
s.store.Add(core.AndroidSuccessKey, count)
|
||||
}
|
||||
|
||||
// AddAndroidError record counts of error Android push notification.
|
||||
func (s *StateStorage) AddAndroidError(count int64) {
|
||||
s.store.Add(storage.AndroidErrorKey, count)
|
||||
s.store.Add(core.AndroidErrorKey, count)
|
||||
}
|
||||
|
||||
// AddHuaweiSuccess record counts of success Huawei push notification.
|
||||
func (s *StateStorage) AddHuaweiSuccess(count int64) {
|
||||
s.store.Add(storage.HuaweiSuccessKey, count)
|
||||
s.store.Add(core.HuaweiSuccessKey, count)
|
||||
}
|
||||
|
||||
// AddHuaweiError record counts of error Huawei push notification.
|
||||
func (s *StateStorage) AddHuaweiError(count int64) {
|
||||
s.store.Add(storage.HuaweiErrorKey, count)
|
||||
s.store.Add(core.HuaweiErrorKey, count)
|
||||
}
|
||||
|
||||
// GetTotalCount show counts of all notification.
|
||||
func (s *StateStorage) GetTotalCount() int64 {
|
||||
return s.store.Get(storage.TotalCountKey)
|
||||
return s.store.Get(core.TotalCountKey)
|
||||
}
|
||||
|
||||
// GetIosSuccess show success counts of iOS notification.
|
||||
func (s *StateStorage) GetIosSuccess() int64 {
|
||||
return s.store.Get(storage.IosSuccessKey)
|
||||
return s.store.Get(core.IosSuccessKey)
|
||||
}
|
||||
|
||||
// GetIosError show error counts of iOS notification.
|
||||
func (s *StateStorage) GetIosError() int64 {
|
||||
return s.store.Get(storage.IosErrorKey)
|
||||
return s.store.Get(core.IosErrorKey)
|
||||
}
|
||||
|
||||
// GetAndroidSuccess show success counts of Android notification.
|
||||
func (s *StateStorage) GetAndroidSuccess() int64 {
|
||||
return s.store.Get(storage.AndroidSuccessKey)
|
||||
return s.store.Get(core.AndroidSuccessKey)
|
||||
}
|
||||
|
||||
// GetAndroidError show error counts of Android notification.
|
||||
func (s *StateStorage) GetAndroidError() int64 {
|
||||
return s.store.Get(storage.AndroidErrorKey)
|
||||
return s.store.Get(core.AndroidErrorKey)
|
||||
}
|
||||
|
||||
// GetHuaweiSuccess show success counts of Huawei notification.
|
||||
func (s *StateStorage) GetHuaweiSuccess() int64 {
|
||||
return s.store.Get(storage.HuaweiSuccessKey)
|
||||
return s.store.Get(core.HuaweiSuccessKey)
|
||||
}
|
||||
|
||||
// GetHuaweiError show error counts of Huawei notification.
|
||||
func (s *StateStorage) GetHuaweiError() int64 {
|
||||
return s.store.Get(storage.HuaweiErrorKey)
|
||||
return s.store.Get(core.HuaweiErrorKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user