Merge pull request #4651 from Loyalsoldier/cache-fix-lint
Fix lint and format code in client/cache dir
This commit is contained in:
commit
c8e81e5a95
@ -67,4 +67,5 @@
|
|||||||
|
|
||||||
## Fix lint and format code
|
## Fix lint and format code
|
||||||
|
|
||||||
|
- [4651](https://github.com/beego/beego/pull/4651)
|
||||||
- [4644](https://github.com/beego/beego/pull/4644)
|
- [4644](https://github.com/beego/beego/pull/4644)
|
||||||
|
|||||||
28
client/cache/conv_test.go
vendored
28
client/cache/conv_test.go
vendored
@ -21,29 +21,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetString(t *testing.T) {
|
func TestGetString(t *testing.T) {
|
||||||
var t1 = "test1"
|
t1 := "test1"
|
||||||
|
|
||||||
assert.Equal(t, "test1", GetString(t1))
|
assert.Equal(t, "test1", GetString(t1))
|
||||||
var t2 = []byte("test2")
|
t2 := []byte("test2")
|
||||||
assert.Equal(t, "test2", GetString(t2))
|
assert.Equal(t, "test2", GetString(t2))
|
||||||
var t3 = 1
|
t3 := 1
|
||||||
assert.Equal(t, "1", GetString(t3))
|
assert.Equal(t, "1", GetString(t3))
|
||||||
var t4 int64 = 1
|
var t4 int64 = 1
|
||||||
assert.Equal(t, "1", GetString(t4))
|
assert.Equal(t, "1", GetString(t4))
|
||||||
var t5 = 1.1
|
t5 := 1.1
|
||||||
assert.Equal(t, "1.1", GetString(t5))
|
assert.Equal(t, "1.1", GetString(t5))
|
||||||
assert.Equal(t, "", GetString(nil))
|
assert.Equal(t, "", GetString(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInt(t *testing.T) {
|
func TestGetInt(t *testing.T) {
|
||||||
var t1 = 1
|
t1 := 1
|
||||||
assert.Equal(t, 1, GetInt(t1))
|
assert.Equal(t, 1, GetInt(t1))
|
||||||
var t2 int32 = 32
|
var t2 int32 = 32
|
||||||
assert.Equal(t, 32, GetInt(t2))
|
assert.Equal(t, 32, GetInt(t2))
|
||||||
|
|
||||||
var t3 int64 = 64
|
var t3 int64 = 64
|
||||||
assert.Equal(t, 64, GetInt(t3))
|
assert.Equal(t, 64, GetInt(t3))
|
||||||
var t4 = "128"
|
t4 := "128"
|
||||||
|
|
||||||
assert.Equal(t, 128, GetInt(t4))
|
assert.Equal(t, 128, GetInt(t4))
|
||||||
assert.Equal(t, 0, GetInt(nil))
|
assert.Equal(t, 0, GetInt(nil))
|
||||||
@ -51,38 +51,38 @@ func TestGetInt(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetInt64(t *testing.T) {
|
func TestGetInt64(t *testing.T) {
|
||||||
var i int64 = 1
|
var i int64 = 1
|
||||||
var t1 = 1
|
t1 := 1
|
||||||
assert.Equal(t, i, GetInt64(t1))
|
assert.Equal(t, i, GetInt64(t1))
|
||||||
var t2 int32 = 1
|
var t2 int32 = 1
|
||||||
|
|
||||||
assert.Equal(t, i, GetInt64(t2))
|
assert.Equal(t, i, GetInt64(t2))
|
||||||
var t3 int64 = 1
|
var t3 int64 = 1
|
||||||
assert.Equal(t, i, GetInt64(t3))
|
assert.Equal(t, i, GetInt64(t3))
|
||||||
var t4 = "1"
|
t4 := "1"
|
||||||
assert.Equal(t, i, GetInt64(t4))
|
assert.Equal(t, i, GetInt64(t4))
|
||||||
assert.Equal(t, int64(0), GetInt64(nil))
|
assert.Equal(t, int64(0), GetInt64(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFloat64(t *testing.T) {
|
func TestGetFloat64(t *testing.T) {
|
||||||
var f = 1.11
|
f := 1.11
|
||||||
var t1 float32 = 1.11
|
var t1 float32 = 1.11
|
||||||
assert.Equal(t, f, GetFloat64(t1))
|
assert.Equal(t, f, GetFloat64(t1))
|
||||||
var t2 = 1.11
|
t2 := 1.11
|
||||||
assert.Equal(t, f, GetFloat64(t2))
|
assert.Equal(t, f, GetFloat64(t2))
|
||||||
var t3 = "1.11"
|
t3 := "1.11"
|
||||||
assert.Equal(t, f, GetFloat64(t3))
|
assert.Equal(t, f, GetFloat64(t3))
|
||||||
|
|
||||||
var f2 float64 = 1
|
var f2 float64 = 1
|
||||||
var t4 = 1
|
t4 := 1
|
||||||
assert.Equal(t, f2, GetFloat64(t4))
|
assert.Equal(t, f2, GetFloat64(t4))
|
||||||
|
|
||||||
assert.Equal(t, float64(0), GetFloat64(nil))
|
assert.Equal(t, float64(0), GetFloat64(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBool(t *testing.T) {
|
func TestGetBool(t *testing.T) {
|
||||||
var t1 = true
|
t1 := true
|
||||||
assert.True(t, GetBool(t1))
|
assert.True(t, GetBool(t1))
|
||||||
var t2 = "true"
|
t2 := "true"
|
||||||
assert.True(t, GetBool(t2))
|
assert.True(t, GetBool(t2))
|
||||||
|
|
||||||
assert.False(t, GetBool(nil))
|
assert.False(t, GetBool(nil))
|
||||||
|
|||||||
6
client/cache/error_code.go
vendored
6
client/cache/error_code.go
vendored
@ -170,5 +170,7 @@ The reponse from SSDB server is invalid.
|
|||||||
Usually it indicates something wrong on server side.
|
Usually it indicates something wrong on server side.
|
||||||
`)
|
`)
|
||||||
|
|
||||||
var ErrKeyExpired = berror.Error(KeyExpired, "the key is expired")
|
var (
|
||||||
var ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
|
ErrKeyExpired = berror.Error(KeyExpired, "the key is expired")
|
||||||
|
ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
|
||||||
|
)
|
||||||
|
|||||||
1
client/cache/file.go
vendored
1
client/cache/file.go
vendored
@ -67,7 +67,6 @@ func NewFileCache() Cache {
|
|||||||
// StartAndGC starts gc for file cache.
|
// StartAndGC starts gc for file cache.
|
||||||
// config must be in the format {CachePath:"/cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}
|
// config must be in the format {CachePath:"/cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}
|
||||||
func (fc *FileCache) StartAndGC(config string) error {
|
func (fc *FileCache) StartAndGC(config string) error {
|
||||||
|
|
||||||
cfg := make(map[string]string)
|
cfg := make(map[string]string)
|
||||||
err := json.Unmarshal([]byte(config), &cfg)
|
err := json.Unmarshal([]byte(config), &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
6
client/cache/memory.go
vendored
6
client/cache/memory.go
vendored
@ -25,10 +25,8 @@ import (
|
|||||||
"github.com/beego/beego/v2/core/berror"
|
"github.com/beego/beego/v2/core/berror"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// DefaultEvery sets a timer for how often to recycle the expired cache items in memory (in seconds)
|
||||||
// Timer for how often to recycle the expired cache items in memory (in seconds)
|
var DefaultEvery = 60 // 1 minute
|
||||||
DefaultEvery = 60 // 1 minute
|
|
||||||
)
|
|
||||||
|
|
||||||
// MemoryItem stores memory cache item.
|
// MemoryItem stores memory cache item.
|
||||||
type MemoryItem struct {
|
type MemoryItem struct {
|
||||||
|
|||||||
6
client/cache/redis/redis.go
vendored
6
client/cache/redis/redis.go
vendored
@ -43,10 +43,8 @@ import (
|
|||||||
"github.com/beego/beego/v2/core/berror"
|
"github.com/beego/beego/v2/core/berror"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// DefaultKey defines the collection name of redis for the cache adapter.
|
||||||
// The collection name of redis for the cache adapter.
|
var DefaultKey = "beecacheRedis"
|
||||||
DefaultKey = "beecacheRedis"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cache is Redis cache adapter.
|
// Cache is Redis cache adapter.
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
|
|||||||
1
client/cache/redis/redis_test.go
vendored
1
client/cache/redis/redis_test.go
vendored
@ -28,7 +28,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRedisCache(t *testing.T) {
|
func TestRedisCache(t *testing.T) {
|
||||||
|
|
||||||
redisAddr := os.Getenv("REDIS_ADDR")
|
redisAddr := os.Getenv("REDIS_ADDR")
|
||||||
if redisAddr == "" {
|
if redisAddr == "" {
|
||||||
redisAddr = "127.0.0.1:6379"
|
redisAddr = "127.0.0.1:6379"
|
||||||
|
|||||||
1
client/cache/ssdb/ssdb.go
vendored
1
client/cache/ssdb/ssdb.go
vendored
@ -124,7 +124,6 @@ func (rc *Cache) IsExist(ctx context.Context, key string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearAll clears all cached items in ssdb.
|
// ClearAll clears all cached items in ssdb.
|
||||||
|
|||||||
1
client/cache/ssdb/ssdb_test.go
vendored
1
client/cache/ssdb/ssdb_test.go
vendored
@ -15,7 +15,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestSsdbcacheCache(t *testing.T) {
|
func TestSsdbcacheCache(t *testing.T) {
|
||||||
|
|
||||||
ssdbAddr := os.Getenv("SSDB_ADDR")
|
ssdbAddr := os.Getenv("SSDB_ADDR")
|
||||||
if ssdbAddr == "" {
|
if ssdbAddr == "" {
|
||||||
ssdbAddr = "127.0.0.1:8888"
|
ssdbAddr = "127.0.0.1:8888"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user