fix lint error in storage folder. (#276)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-08-23 22:25:05 -05:00 committed by GitHub
parent e070248a11
commit 35e2c97f43
7 changed files with 77 additions and 17 deletions

View File

@ -1,6 +1,8 @@
package boltdb
import (
"log"
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/storage"
@ -35,14 +37,32 @@ func (s *Storage) Reset() {
func (s *Storage) setBoltDB(key string, count int64) {
db, _ := storm.Open(s.config.Stat.BoltDB.Path)
db.Set(s.config.Stat.BoltDB.Bucket, key, count)
defer db.Close()
err := db.Set(s.config.Stat.BoltDB.Bucket, key, count)
if err != nil {
log.Println("BoltDB set error:", err.Error())
}
defer func() {
err := db.Close()
if err != nil {
log.Println("BoltDB error:", err.Error())
}
}()
}
func (s *Storage) getBoltDB(key string, count *int64) {
db, _ := storm.Open(s.config.Stat.BoltDB.Path)
db.Get(s.config.Stat.BoltDB.Bucket, key, count)
defer db.Close()
err := db.Get(s.config.Stat.BoltDB.Bucket, key, count)
if err != nil {
log.Println("BoltDB get error:", err.Error())
}
defer func() {
err := db.Close()
if err != nil {
log.Println("BoltDB error:", err.Error())
}
}()
}
// AddTotalCount record push notification count.

View File

@ -13,7 +13,8 @@ func TestBoltDBEngine(t *testing.T) {
config := c.BuildDefaultPushConf()
boltDB := New(config)
boltDB.Init()
err := boltDB.Init()
assert.Nil(t, err)
boltDB.Reset()
boltDB.AddTotalCount(10)

View File

@ -2,6 +2,7 @@ package buntdb
import (
"fmt"
"log"
"strconv"
"github.com/appleboy/gorush/config"
@ -39,22 +40,44 @@ func (s *Storage) Reset() {
func (s *Storage) setBuntDB(key string, count int64) {
db, _ := buntdb.Open(s.config.Stat.BuntDB.Path)
db.Update(func(tx *buntdb.Tx) error {
tx.Set(key, fmt.Sprintf("%d", count), nil)
err := db.Update(func(tx *buntdb.Tx) error {
if _, _, err := tx.Set(key, fmt.Sprintf("%d", count), nil); err != nil {
return err
}
return nil
})
defer db.Close()
if err != nil {
log.Println("BuntDB update error:", err.Error())
}
defer func() {
err := db.Close()
if err != nil {
log.Println("BuntDB error:", err.Error())
}
}()
}
func (s *Storage) getBuntDB(key string, count *int64) {
db, _ := buntdb.Open(s.config.Stat.BuntDB.Path)
db.View(func(tx *buntdb.Tx) error {
err := db.View(func(tx *buntdb.Tx) error {
val, _ := tx.Get(key)
*count, _ = strconv.ParseInt(val, 10, 64)
return nil
})
defer db.Close()
if err != nil {
log.Println("BuntDB get error:", err.Error())
}
defer func() {
err := db.Close()
if err != nil {
log.Println("BuntDB error:", err.Error())
}
}()
}
// AddTotalCount record push notification count.

View File

@ -14,11 +14,13 @@ func TestBuntDBEngine(t *testing.T) {
config := c.BuildDefaultPushConf()
if _, err := os.Stat(config.Stat.BuntDB.Path); os.IsNotExist(err) {
os.RemoveAll(config.Stat.BuntDB.Path)
err := os.RemoveAll(config.Stat.BuntDB.Path)
assert.Nil(t, err)
}
buntDB := New(config)
buntDB.Init()
err := buntDB.Init()
assert.Nil(t, err)
buntDB.Reset()
buntDB.AddTotalCount(10)

View File

@ -2,6 +2,7 @@ package leveldb
import (
"fmt"
"log"
"strconv"
"github.com/appleboy/gorush/config"
@ -18,7 +19,12 @@ func setLevelDB(key string, count int64) {
_ = db.Put([]byte(key), []byte(value), nil)
defer db.Close()
defer func() {
err := db.Close()
if err != nil {
log.Println("LevelDB error:", err.Error())
}
}()
}
func getLevelDB(key string, count *int64) {
@ -27,7 +33,12 @@ func getLevelDB(key string, count *int64) {
data, _ := db.Get([]byte(key), nil)
*count, _ = strconv.ParseInt(string(data), 10, 64)
defer db.Close()
defer func() {
err := db.Close()
if err != nil {
log.Println("LevelDB error:", err.Error())
}
}()
}
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)

View File

@ -14,11 +14,13 @@ func TestLevelDBEngine(t *testing.T) {
config := c.BuildDefaultPushConf()
if _, err := os.Stat(config.Stat.LevelDB.Path); os.IsNotExist(err) {
os.RemoveAll(config.Stat.LevelDB.Path)
err = os.RemoveAll(config.Stat.LevelDB.Path)
assert.Nil(t, err)
}
levelDB := New(config)
levelDB.Init()
err := levelDB.Init()
assert.Nil(t, err)
levelDB.Reset()
levelDB.AddTotalCount(10)

View File

@ -24,7 +24,8 @@ func TestRedisEngine(t *testing.T) {
config.Stat.Redis.Addr = "redis:6379"
redis := New(config)
redis.Init()
err := redis.Init()
assert.Nil(t, err)
redis.Reset()
redis.AddTotalCount(10)