integrate memory engine.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -1,66 +1,84 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"github.com/appleboy/gorush/gorush"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// StatusApp is app status structure
|
||||
type statApp struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
Ios IosStatus `json:"ios"`
|
||||
Android AndroidStatus `json:"android"`
|
||||
}
|
||||
|
||||
// AndroidStatus is android structure
|
||||
type AndroidStatus struct {
|
||||
PushSuccess int64 `json:"push_success"`
|
||||
PushError int64 `json:"push_error"`
|
||||
}
|
||||
|
||||
// IosStatus is iOS structure
|
||||
type IosStatus struct {
|
||||
PushSuccess int64 `json:"push_success"`
|
||||
PushError int64 `json:"push_error"`
|
||||
}
|
||||
|
||||
// Storage implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
||||
func New(stat gorush.StatusApp) *Storage {
|
||||
func New() *Storage {
|
||||
return &Storage{
|
||||
stat: stat,
|
||||
stat: &statApp{},
|
||||
}
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
stat gorush.StatusApp
|
||||
stat *statApp
|
||||
}
|
||||
|
||||
func (s *Storage) addTotalCount(count int64) {
|
||||
func (s *Storage) AddTotalCount(count int64) {
|
||||
atomic.AddInt64(&s.stat.TotalCount, count)
|
||||
}
|
||||
|
||||
func (s *Storage) addIosSuccess(count int64) {
|
||||
func (s *Storage) AddIosSuccess(count int64) {
|
||||
atomic.AddInt64(&s.stat.Ios.PushSuccess, count)
|
||||
}
|
||||
|
||||
func (s *Storage) addIosError(count int64) {
|
||||
func (s *Storage) AddIosError(count int64) {
|
||||
atomic.AddInt64(&s.stat.Ios.PushError, count)
|
||||
}
|
||||
|
||||
func (s *Storage) addAndroidSuccess(count int64) {
|
||||
func (s *Storage) AddAndroidSuccess(count int64) {
|
||||
atomic.AddInt64(&s.stat.Android.PushSuccess, count)
|
||||
}
|
||||
|
||||
func (s *Storage) addAndroidError(count int64) {
|
||||
func (s *Storage) AddAndroidError(count int64) {
|
||||
atomic.AddInt64(&s.stat.Android.PushError, count)
|
||||
}
|
||||
|
||||
func (s *Storage) getTotalCount() int64 {
|
||||
func (s *Storage) GetTotalCount() int64 {
|
||||
count := atomic.LoadInt64(&s.stat.TotalCount)
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func (s *Storage) getIosSuccess() int64 {
|
||||
func (s *Storage) GetIosSuccess() int64 {
|
||||
count := atomic.LoadInt64(&s.stat.Ios.PushSuccess)
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func (s *Storage) getIosError() int64 {
|
||||
func (s *Storage) GetIosError() int64 {
|
||||
count := atomic.LoadInt64(&s.stat.Ios.PushError)
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func (s *Storage) getAndroidSuccess() int64 {
|
||||
func (s *Storage) GetAndroidSuccess() int64 {
|
||||
count := atomic.LoadInt64(&s.stat.Android.PushSuccess)
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func (s *Storage) getAndroidError() int64 {
|
||||
func (s *Storage) GetAndroidError() int64 {
|
||||
count := atomic.LoadInt64(&s.stat.Android.PushError)
|
||||
|
||||
return count
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"github.com/appleboy/gorush/gorush"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
@@ -9,25 +8,25 @@ import (
|
||||
func TestMemoryEngine(t *testing.T) {
|
||||
var val int64
|
||||
|
||||
memory := New(gorush.StatusApp{})
|
||||
memory := New()
|
||||
|
||||
memory.addTotalCount(1)
|
||||
val = memory.getTotalCount()
|
||||
memory.AddTotalCount(1)
|
||||
val = memory.GetTotalCount()
|
||||
assert.Equal(t, int64(1), val)
|
||||
|
||||
memory.addIosSuccess(2)
|
||||
val = memory.getIosSuccess()
|
||||
memory.AddIosSuccess(2)
|
||||
val = memory.GetIosSuccess()
|
||||
assert.Equal(t, int64(2), val)
|
||||
|
||||
memory.addIosError(3)
|
||||
val = memory.getIosError()
|
||||
memory.AddIosError(3)
|
||||
val = memory.GetIosError()
|
||||
assert.Equal(t, int64(3), val)
|
||||
|
||||
memory.addAndroidSuccess(4)
|
||||
val = memory.getAndroidSuccess()
|
||||
memory.AddAndroidSuccess(4)
|
||||
val = memory.GetAndroidSuccess()
|
||||
assert.Equal(t, int64(4), val)
|
||||
|
||||
memory.addAndroidError(5)
|
||||
val = memory.getAndroidError()
|
||||
memory.AddAndroidError(5)
|
||||
val = memory.GetAndroidError()
|
||||
assert.Equal(t, int64(5), val)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user