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

@@ -2,16 +2,9 @@ package boltdb
import (
"github.com/appleboy/gorush/config"
"github.com/asdine/storm"
)
"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/asdine/storm"
)
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
@@ -33,11 +26,11 @@ func (s *Storage) Init() error {
// Reset Client storage.
func (s *Storage) Reset() {
s.setBoltDB(TotalCountKey, 0)
s.setBoltDB(IosSuccessKey, 0)
s.setBoltDB(IosErrorKey, 0)
s.setBoltDB(AndroidSuccessKey, 0)
s.setBoltDB(AndroidErrorKey, 0)
s.setBoltDB(storage.TotalCountKey, 0)
s.setBoltDB(storage.IosSuccessKey, 0)
s.setBoltDB(storage.IosErrorKey, 0)
s.setBoltDB(storage.AndroidSuccessKey, 0)
s.setBoltDB(storage.AndroidErrorKey, 0)
}
func (s *Storage) setBoltDB(key string, count int64) {
@@ -55,37 +48,37 @@ func (s *Storage) getBoltDB(key string, count *int64) {
// AddTotalCount record push notification count.
func (s *Storage) AddTotalCount(count int64) {
total := s.GetTotalCount() + count
s.setBoltDB(TotalCountKey, total)
s.setBoltDB(storage.TotalCountKey, total)
}
// AddIosSuccess record counts of success iOS push notification.
func (s *Storage) AddIosSuccess(count int64) {
total := s.GetIosSuccess() + count
s.setBoltDB(IosSuccessKey, total)
s.setBoltDB(storage.IosSuccessKey, total)
}
// AddIosError record counts of error iOS push notification.
func (s *Storage) AddIosError(count int64) {
total := s.GetIosError() + count
s.setBoltDB(IosErrorKey, total)
s.setBoltDB(storage.IosErrorKey, total)
}
// AddAndroidSuccess record counts of success Android push notification.
func (s *Storage) AddAndroidSuccess(count int64) {
total := s.GetAndroidSuccess() + count
s.setBoltDB(AndroidSuccessKey, total)
s.setBoltDB(storage.AndroidSuccessKey, total)
}
// AddAndroidError record counts of error Android push notification.
func (s *Storage) AddAndroidError(count int64) {
total := s.GetAndroidError() + count
s.setBoltDB(AndroidErrorKey, total)
s.setBoltDB(storage.AndroidErrorKey, total)
}
// GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 {
var count int64
s.getBoltDB(TotalCountKey, &count)
s.getBoltDB(storage.TotalCountKey, &count)
return count
}
@@ -93,7 +86,7 @@ func (s *Storage) GetTotalCount() int64 {
// GetIosSuccess show success counts of iOS notification.
func (s *Storage) GetIosSuccess() int64 {
var count int64
s.getBoltDB(IosSuccessKey, &count)
s.getBoltDB(storage.IosSuccessKey, &count)
return count
}
@@ -101,7 +94,7 @@ func (s *Storage) GetIosSuccess() int64 {
// GetIosError show error counts of iOS notification.
func (s *Storage) GetIosError() int64 {
var count int64
s.getBoltDB(IosErrorKey, &count)
s.getBoltDB(storage.IosErrorKey, &count)
return count
}
@@ -109,7 +102,7 @@ func (s *Storage) GetIosError() int64 {
// GetAndroidSuccess show success counts of Android notification.
func (s *Storage) GetAndroidSuccess() int64 {
var count int64
s.getBoltDB(AndroidSuccessKey, &count)
s.getBoltDB(storage.AndroidSuccessKey, &count)
return count
}
@@ -117,7 +110,7 @@ func (s *Storage) GetAndroidSuccess() int64 {
// GetAndroidError show error counts of Android notification.
func (s *Storage) GetAndroidError() int64 {
var count int64
s.getBoltDB(AndroidErrorKey, &count)
s.getBoltDB(storage.AndroidErrorKey, &count)
return count
}