Chore: format code

This commit is contained in:
loyalsoldier
2021-05-18 23:16:04 +08:00
parent 8f9eccefe9
commit 2b7401109f
33 changed files with 51 additions and 76 deletions

View File

@@ -99,9 +99,7 @@ func TestCache(t *testing.T) {
vv, _ := bm.GetMulti(context.Background(), []string{"astaxie", "astaxie1"})
assert.Equal(t, 2, len(vv))
assert.Equal(t, "author", vv[0])
assert.Equal(t,"author1", vv[1])
assert.Equal(t, "author1", vv[1])
vv, err = bm.GetMulti(context.Background(), []string{"astaxie0", "astaxie1"})
assert.Equal(t, 2, len(vv))
@@ -116,7 +114,7 @@ func TestFileCache(t *testing.T) {
bm, err := NewCache("file", `{"CachePath":"cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}`)
assert.Nil(t, err)
timeoutDuration := 10 * time.Second
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
res, _ := bm.IsExist(context.Background(), "astaxie")
assert.True(t, res)
@@ -179,7 +177,6 @@ func testIncrDecr(t *testing.T, c Cache, beforeIncr interface{}, afterIncr inter
assert.Nil(t, c.Put(ctx, key, beforeIncr, timeout))
assert.Nil(t, c.Incr(ctx, key))
v, _ := c.Get(ctx, key)
assert.Equal(t, afterIncr, v)

View File

@@ -9,11 +9,9 @@ import (
var (
ErrIncrementOverflow = berror.Error(IncrementOverflow, "this incr invocation will overflow.")
ErrDecrementOverflow = berror.Error(DecrementOverflow, "this decr invocation will overflow.")
ErrNotIntegerType = berror.Error(NotIntegerType, "item val is not (u)int (u)int32 (u)int64")
ErrNotIntegerType = berror.Error(NotIntegerType, "item val is not (u)int (u)int32 (u)int64")
)
func incr(originVal interface{}) (interface{}, error) {
switch val := originVal.(type) {
case int:

View File

@@ -123,14 +123,6 @@ var InvalidSsdbCacheValue = berror.DefineCode(4002022, moduleName, "InvalidSsdbC
SSDB cache only accept string value. Please check your input.
`)
var DeleteFileCacheItemFailed = berror.DefineCode(5002001, moduleName, "DeleteFileCacheItemFailed", `
Beego try to delete file cache item failed.
Please check whether Beego generated file correctly.
@@ -179,4 +171,4 @@ Usually it indicates something wrong on server side.
`)
var ErrKeyExpired = berror.Error(KeyExpired, "the key is expired")
var ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
var ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")

View File

@@ -140,7 +140,7 @@ func (fc *FileCache) getCacheFileName(key string) (string, error) {
return "", err
}
if !ok {
err = os.MkdirAll(cachePath, os.ModePerm)
err = os.MkdirAll(cachePath, os.ModePerm)
if err != nil {
return "", berror.Wrapf(err, CreateFileCacheDirFailed,
"could not create the directory: %s", cachePath)
@@ -299,8 +299,8 @@ func FileGetContents(filename string) ([]byte, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, berror.Wrapf(err, ReadFileCacheContentFailed,
"could not read the data from the file: %s, " +
"please confirm that file exist and Beego has the permission to read the content.", filename)
"could not read the data from the file: %s, "+
"please confirm that file exist and Beego has the permission to read the content.", filename)
}
return data, nil
}

View File

@@ -105,4 +105,4 @@ func TestFileCacheDelete(t *testing.T) {
func getTestCacheFilePath() string {
return filepath.Join(os.TempDir(), "test", "file.txt")
}
}

View File

@@ -71,8 +71,8 @@ func (rc *Cache) GetMulti(ctx context.Context, keys []string) ([]interface{}, er
mv, err := rc.conn.GetMulti(keys)
if err != nil {
return rv, berror.Wrapf(err, cache.MemCacheCurdFailed,
"could not read multiple key-values from memcache, " +
"please check your keys, network and connection. Root cause: %s",
"could not read multiple key-values from memcache, "+
"please check your keys, network and connection. Root cause: %s",
err.Error())
}

View File

@@ -74,7 +74,7 @@ func TestMemcacheCache(t *testing.T) {
res, _ = bm.IsExist(context.Background(), "astaxie")
assert.False(t, res)
assert.Nil(t,bm.Put(context.Background(), "astaxie", "author", timeoutDuration) )
assert.Nil(t, bm.Put(context.Background(), "astaxie", "author", timeoutDuration))
// test string
res, _ = bm.IsExist(context.Background(), "astaxie")
assert.True(t, res)
@@ -86,7 +86,6 @@ func TestMemcacheCache(t *testing.T) {
// test GetMulti
assert.Nil(t, bm.Put(context.Background(), "astaxie1", "author1", timeoutDuration))
res, _ = bm.IsExist(context.Background(), "astaxie1")
assert.True(t, res)

View File

@@ -40,7 +40,6 @@ func TestRedisCache(t *testing.T) {
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
res, _ := bm.IsExist(context.Background(), "astaxie")
assert.True(t, res)
@@ -51,7 +50,6 @@ func TestRedisCache(t *testing.T) {
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
val, _ := bm.Get(context.Background(), "astaxie")
v, _ := redis.Int(val, err)
assert.Equal(t, 1, v)

View File

@@ -30,7 +30,7 @@ func TestSsdbcacheCache(t *testing.T) {
timeoutDuration := 3 * time.Second
// timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
assert.Nil(t, ssdb.Put(context.Background(), "ssdb", "ssdb", timeoutDuration))
assert.Nil(t, ssdb.Put(context.Background(), "ssdb", "ssdb", timeoutDuration))
res, _ = ssdb.IsExist(context.Background(), "ssdb")
assert.True(t, res)
@@ -87,7 +87,7 @@ func TestSsdbcacheCache(t *testing.T) {
assert.Equal(t, 2, len(vv))
assert.Equal(t, "ssdb", vv[0])
assert.Nil(t, vv[1])
assert.Nil(t, vv[1])
assert.NotNil(t, err)
assert.True(t, strings.Contains(err.Error(), "key not exist"))