refactor: storage key. (#242)

* refactor: storage key.

* fix path

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-06-24 11:48:48 -05:00
committed by GitHub
parent 16c3f5c46c
commit 45a3ca891e
6 changed files with 86 additions and 97 deletions

View File

@@ -5,16 +5,9 @@ import (
"strconv"
"github.com/appleboy/gorush/config"
"github.com/tidwall/buntdb"
)
"github.com/appleboy/gorush/storage"
// Stat variable for redis
const (
TotalCountKey = "gorush-total-count"
IosSuccessKey = "gorush-ios-success-count"
IosErrorKey = "gorush-ios-error-count"
AndroidSuccessKey = "gorush-android-success-count"
AndroidErrorKey = "gorush-android-error-count"
"github.com/tidwall/buntdb"
)
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
@@ -36,11 +29,11 @@ func (s *Storage) Init() error {
// Reset Client storage.
func (s *Storage) Reset() {
s.setBuntDB(TotalCountKey, 0)
s.setBuntDB(IosSuccessKey, 0)
s.setBuntDB(IosErrorKey, 0)
s.setBuntDB(AndroidSuccessKey, 0)
s.setBuntDB(AndroidErrorKey, 0)
s.setBuntDB(storage.TotalCountKey, 0)
s.setBuntDB(storage.IosSuccessKey, 0)
s.setBuntDB(storage.IosErrorKey, 0)
s.setBuntDB(storage.AndroidSuccessKey, 0)
s.setBuntDB(storage.AndroidErrorKey, 0)
}
func (s *Storage) setBuntDB(key string, count int64) {
@@ -67,37 +60,37 @@ func (s *Storage) getBuntDB(key string, count *int64) {
// AddTotalCount record push notification count.
func (s *Storage) AddTotalCount(count int64) {
total := s.GetTotalCount() + count
s.setBuntDB(TotalCountKey, total)
s.setBuntDB(storage.TotalCountKey, total)
}
// AddIosSuccess record counts of success iOS push notification.
func (s *Storage) AddIosSuccess(count int64) {
total := s.GetIosSuccess() + count
s.setBuntDB(IosSuccessKey, total)
s.setBuntDB(storage.IosSuccessKey, total)
}
// AddIosError record counts of error iOS push notification.
func (s *Storage) AddIosError(count int64) {
total := s.GetIosError() + count
s.setBuntDB(IosErrorKey, total)
s.setBuntDB(storage.IosErrorKey, total)
}
// AddAndroidSuccess record counts of success Android push notification.
func (s *Storage) AddAndroidSuccess(count int64) {
total := s.GetAndroidSuccess() + count
s.setBuntDB(AndroidSuccessKey, total)
s.setBuntDB(storage.AndroidSuccessKey, total)
}
// AddAndroidError record counts of error Android push notification.
func (s *Storage) AddAndroidError(count int64) {
total := s.GetAndroidError() + count
s.setBuntDB(AndroidErrorKey, total)
s.setBuntDB(storage.AndroidErrorKey, total)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
s.getBuntDB(TotalCountKey, &count)
s.getBuntDB(storage.TotalCountKey, &count)
return count
}
@@ -105,7 +98,7 @@ func (s *Storage) GetTotalCount() int64 {
// GetIosSuccess show success counts of iOS notification.
func (s *Storage) GetIosSuccess() int64 {
var count int64
s.getBuntDB(IosSuccessKey, &count)
s.getBuntDB(storage.IosSuccessKey, &count)
return count
}
@@ -113,7 +106,7 @@ func (s *Storage) GetIosSuccess() int64 {
// GetIosError show error counts of iOS notification.
func (s *Storage) GetIosError() int64 {
var count int64
s.getBuntDB(IosErrorKey, &count)
s.getBuntDB(storage.IosErrorKey, &count)
return count
}
@@ -121,7 +114,7 @@ func (s *Storage) GetIosError() int64 {
// GetAndroidSuccess show success counts of Android notification.
func (s *Storage) GetAndroidSuccess() int64 {
var count int64
s.getBuntDB(AndroidSuccessKey, &count)
s.getBuntDB(storage.AndroidSuccessKey, &count)
return count
}
@@ -129,7 +122,7 @@ func (s *Storage) GetAndroidSuccess() int64 {
// GetAndroidError show error counts of Android notification.
func (s *Storage) GetAndroidError() int64 {
var count int64
s.getBuntDB(AndroidErrorKey, &count)
s.getBuntDB(storage.AndroidErrorKey, &count)
return count
}