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

@ -14,8 +14,8 @@ pipeline:
secrets: [ codecov_token, android_test_token, android_api_key ] secrets: [ codecov_token, android_test_token, android_api_key ]
environment: environment:
- GOPATH=/srv/app - GOPATH=/srv/app
- PATH=$${PATH}:/srv/app/bin
commands: commands:
- export PATH=$${PATH}:/srv/app/bin
- make deps - make deps
- make vet - make vet
- make lint - make lint

View File

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

View File

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

View File

@ -5,16 +5,9 @@ import (
"strconv" "strconv"
"github.com/appleboy/gorush/config" "github.com/appleboy/gorush/config"
"github.com/syndtr/goleveldb/leveldb" "github.com/appleboy/gorush/storage"
)
// Stat variable for redis "github.com/syndtr/goleveldb/leveldb"
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"
) )
var dbPath string var dbPath string
@ -57,47 +50,47 @@ func (s *Storage) Init() error {
// Reset Client storage. // Reset Client storage.
func (s *Storage) Reset() { func (s *Storage) Reset() {
setLevelDB(TotalCountKey, 0) setLevelDB(storage.TotalCountKey, 0)
setLevelDB(IosSuccessKey, 0) setLevelDB(storage.IosSuccessKey, 0)
setLevelDB(IosErrorKey, 0) setLevelDB(storage.IosErrorKey, 0)
setLevelDB(AndroidSuccessKey, 0) setLevelDB(storage.AndroidSuccessKey, 0)
setLevelDB(AndroidErrorKey, 0) setLevelDB(storage.AndroidErrorKey, 0)
} }
// AddTotalCount record push notification count. // AddTotalCount record push notification count.
func (s *Storage) AddTotalCount(count int64) { func (s *Storage) AddTotalCount(count int64) {
total := s.GetTotalCount() + count total := s.GetTotalCount() + count
setLevelDB(TotalCountKey, total) setLevelDB(storage.TotalCountKey, total)
} }
// AddIosSuccess record counts of success iOS push notification. // AddIosSuccess record counts of success iOS push notification.
func (s *Storage) AddIosSuccess(count int64) { func (s *Storage) AddIosSuccess(count int64) {
total := s.GetIosSuccess() + count total := s.GetIosSuccess() + count
setLevelDB(IosSuccessKey, total) setLevelDB(storage.IosSuccessKey, total)
} }
// AddIosError record counts of error iOS push notification. // AddIosError record counts of error iOS push notification.
func (s *Storage) AddIosError(count int64) { func (s *Storage) AddIosError(count int64) {
total := s.GetIosError() + count total := s.GetIosError() + count
setLevelDB(IosErrorKey, total) setLevelDB(storage.IosErrorKey, total)
} }
// AddAndroidSuccess record counts of success Android push notification. // AddAndroidSuccess record counts of success Android push notification.
func (s *Storage) AddAndroidSuccess(count int64) { func (s *Storage) AddAndroidSuccess(count int64) {
total := s.GetAndroidSuccess() + count total := s.GetAndroidSuccess() + count
setLevelDB(AndroidSuccessKey, total) setLevelDB(storage.AndroidSuccessKey, total)
} }
// AddAndroidError record counts of error Android push notification. // AddAndroidError record counts of error Android push notification.
func (s *Storage) AddAndroidError(count int64) { func (s *Storage) AddAndroidError(count int64) {
total := s.GetAndroidError() + count total := s.GetAndroidError() + count
setLevelDB(AndroidErrorKey, total) setLevelDB(storage.AndroidErrorKey, total)
} }
// GetTotalCount show counts of all notification. // GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 { func (s *Storage) GetTotalCount() int64 {
var count int64 var count int64
getLevelDB(TotalCountKey, &count) getLevelDB(storage.TotalCountKey, &count)
return count return count
} }
@ -105,7 +98,7 @@ func (s *Storage) GetTotalCount() int64 {
// GetIosSuccess show success counts of iOS notification. // GetIosSuccess show success counts of iOS notification.
func (s *Storage) GetIosSuccess() int64 { func (s *Storage) GetIosSuccess() int64 {
var count int64 var count int64
getLevelDB(IosSuccessKey, &count) getLevelDB(storage.IosSuccessKey, &count)
return count return count
} }
@ -113,7 +106,7 @@ func (s *Storage) GetIosSuccess() int64 {
// GetIosError show error counts of iOS notification. // GetIosError show error counts of iOS notification.
func (s *Storage) GetIosError() int64 { func (s *Storage) GetIosError() int64 {
var count int64 var count int64
getLevelDB(IosErrorKey, &count) getLevelDB(storage.IosErrorKey, &count)
return count return count
} }
@ -121,7 +114,7 @@ func (s *Storage) GetIosError() int64 {
// GetAndroidSuccess show success counts of Android notification. // GetAndroidSuccess show success counts of Android notification.
func (s *Storage) GetAndroidSuccess() int64 { func (s *Storage) GetAndroidSuccess() int64 {
var count int64 var count int64
getLevelDB(AndroidSuccessKey, &count) getLevelDB(storage.AndroidSuccessKey, &count)
return count return count
} }
@ -129,7 +122,7 @@ func (s *Storage) GetAndroidSuccess() int64 {
// GetAndroidError show error counts of Android notification. // GetAndroidError show error counts of Android notification.
func (s *Storage) GetAndroidError() int64 { func (s *Storage) GetAndroidError() int64 {
var count int64 var count int64
getLevelDB(AndroidErrorKey, &count) getLevelDB(storage.AndroidErrorKey, &count)
return count return count
} }

View File

@ -5,16 +5,9 @@ import (
"strconv" "strconv"
"github.com/appleboy/gorush/config" "github.com/appleboy/gorush/config"
"gopkg.in/redis.v5" "github.com/appleboy/gorush/storage"
)
// Stat variable for redis "gopkg.in/redis.v5"
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"
) )
// //
@ -59,47 +52,47 @@ func (s *Storage) Init() error {
// Reset Client storage. // Reset Client storage.
func (s *Storage) Reset() { func (s *Storage) Reset() {
redisClient.Set(TotalCountKey, strconv.Itoa(0), 0) redisClient.Set(storage.TotalCountKey, strconv.Itoa(0), 0)
redisClient.Set(IosSuccessKey, strconv.Itoa(0), 0) redisClient.Set(storage.IosSuccessKey, strconv.Itoa(0), 0)
redisClient.Set(IosErrorKey, strconv.Itoa(0), 0) redisClient.Set(storage.IosErrorKey, strconv.Itoa(0), 0)
redisClient.Set(AndroidSuccessKey, strconv.Itoa(0), 0) redisClient.Set(storage.AndroidSuccessKey, strconv.Itoa(0), 0)
redisClient.Set(AndroidErrorKey, strconv.Itoa(0), 0) redisClient.Set(storage.AndroidErrorKey, strconv.Itoa(0), 0)
} }
// AddTotalCount record push notification count. // AddTotalCount record push notification count.
func (s *Storage) AddTotalCount(count int64) { func (s *Storage) AddTotalCount(count int64) {
total := s.GetTotalCount() + count total := s.GetTotalCount() + count
redisClient.Set(TotalCountKey, strconv.Itoa(int(total)), 0) redisClient.Set(storage.TotalCountKey, strconv.Itoa(int(total)), 0)
} }
// AddIosSuccess record counts of success iOS push notification. // AddIosSuccess record counts of success iOS push notification.
func (s *Storage) AddIosSuccess(count int64) { func (s *Storage) AddIosSuccess(count int64) {
total := s.GetIosSuccess() + count total := s.GetIosSuccess() + count
redisClient.Set(IosSuccessKey, strconv.Itoa(int(total)), 0) redisClient.Set(storage.IosSuccessKey, strconv.Itoa(int(total)), 0)
} }
// AddIosError record counts of error iOS push notification. // AddIosError record counts of error iOS push notification.
func (s *Storage) AddIosError(count int64) { func (s *Storage) AddIosError(count int64) {
total := s.GetIosError() + count total := s.GetIosError() + count
redisClient.Set(IosErrorKey, strconv.Itoa(int(total)), 0) redisClient.Set(storage.IosErrorKey, strconv.Itoa(int(total)), 0)
} }
// AddAndroidSuccess record counts of success Android push notification. // AddAndroidSuccess record counts of success Android push notification.
func (s *Storage) AddAndroidSuccess(count int64) { func (s *Storage) AddAndroidSuccess(count int64) {
total := s.GetAndroidSuccess() + count total := s.GetAndroidSuccess() + count
redisClient.Set(AndroidSuccessKey, strconv.Itoa(int(total)), 0) redisClient.Set(storage.AndroidSuccessKey, strconv.Itoa(int(total)), 0)
} }
// AddAndroidError record counts of error Android push notification. // AddAndroidError record counts of error Android push notification.
func (s *Storage) AddAndroidError(count int64) { func (s *Storage) AddAndroidError(count int64) {
total := s.GetAndroidError() + count total := s.GetAndroidError() + count
redisClient.Set(AndroidErrorKey, strconv.Itoa(int(total)), 0) redisClient.Set(storage.AndroidErrorKey, strconv.Itoa(int(total)), 0)
} }
// GetTotalCount show counts of all notification. // GetTotalCount show counts of all notification.
func (s *Storage) GetTotalCount() int64 { func (s *Storage) GetTotalCount() int64 {
var count int64 var count int64
getInt64(TotalCountKey, &count) getInt64(storage.TotalCountKey, &count)
return count return count
} }
@ -107,7 +100,7 @@ func (s *Storage) GetTotalCount() int64 {
// GetIosSuccess show success counts of iOS notification. // GetIosSuccess show success counts of iOS notification.
func (s *Storage) GetIosSuccess() int64 { func (s *Storage) GetIosSuccess() int64 {
var count int64 var count int64
getInt64(IosSuccessKey, &count) getInt64(storage.IosSuccessKey, &count)
return count return count
} }
@ -115,7 +108,7 @@ func (s *Storage) GetIosSuccess() int64 {
// GetIosError show error counts of iOS notification. // GetIosError show error counts of iOS notification.
func (s *Storage) GetIosError() int64 { func (s *Storage) GetIosError() int64 {
var count int64 var count int64
getInt64(IosErrorKey, &count) getInt64(storage.IosErrorKey, &count)
return count return count
} }
@ -123,7 +116,7 @@ func (s *Storage) GetIosError() int64 {
// GetAndroidSuccess show success counts of Android notification. // GetAndroidSuccess show success counts of Android notification.
func (s *Storage) GetAndroidSuccess() int64 { func (s *Storage) GetAndroidSuccess() int64 {
var count int64 var count int64
getInt64(AndroidSuccessKey, &count) getInt64(storage.AndroidSuccessKey, &count)
return count return count
} }
@ -131,7 +124,7 @@ func (s *Storage) GetAndroidSuccess() int64 {
// GetAndroidError show error counts of Android notification. // GetAndroidError show error counts of Android notification.
func (s *Storage) GetAndroidError() int64 { func (s *Storage) GetAndroidError() int64 {
var count int64 var count int64
getInt64(AndroidErrorKey, &count) getInt64(storage.AndroidErrorKey, &count)
return count return count
} }

View File

@ -1,5 +1,22 @@
package storage package storage
const (
// TotalCountKey is key name for total count of storage
TotalCountKey = "gorush-total-count"
// IosSuccessKey is key name or ios success count of storage
IosSuccessKey = "gorush-ios-success-count"
// IosErrorKey is key name or ios success error of storage
IosErrorKey = "gorush-ios-error-count"
// AndroidSuccessKey is key name for android success count of storage
AndroidSuccessKey = "gorush-android-success-count"
// AndroidErrorKey is key name for android error count of storage
AndroidErrorKey = "gorush-android-error-count"
)
// Storage interface // Storage interface
type Storage interface { type Storage interface {
Init() error Init() error