mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:30:56 +00:00
cache: remove excessive type assertions
Assign type switch variable to get properly-typed value inside case clauses. Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This commit is contained in:
parent
712bbfe575
commit
dc07fa7085
34
cache/memory.go
vendored
34
cache/memory.go
vendored
@ -116,19 +116,19 @@ func (bc *MemoryCache) Incr(key string) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("key not exist")
|
return errors.New("key not exist")
|
||||||
}
|
}
|
||||||
switch itm.val.(type) {
|
switch val := itm.val.(type) {
|
||||||
case int:
|
case int:
|
||||||
itm.val = itm.val.(int) + 1
|
itm.val = val + 1
|
||||||
case int32:
|
case int32:
|
||||||
itm.val = itm.val.(int32) + 1
|
itm.val = val + 1
|
||||||
case int64:
|
case int64:
|
||||||
itm.val = itm.val.(int64) + 1
|
itm.val = val + 1
|
||||||
case uint:
|
case uint:
|
||||||
itm.val = itm.val.(uint) + 1
|
itm.val = val + 1
|
||||||
case uint32:
|
case uint32:
|
||||||
itm.val = itm.val.(uint32) + 1
|
itm.val = val + 1
|
||||||
case uint64:
|
case uint64:
|
||||||
itm.val = itm.val.(uint64) + 1
|
itm.val = val + 1
|
||||||
default:
|
default:
|
||||||
return errors.New("item val is not (u)int (u)int32 (u)int64")
|
return errors.New("item val is not (u)int (u)int32 (u)int64")
|
||||||
}
|
}
|
||||||
@ -143,28 +143,28 @@ func (bc *MemoryCache) Decr(key string) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("key not exist")
|
return errors.New("key not exist")
|
||||||
}
|
}
|
||||||
switch itm.val.(type) {
|
switch val := itm.val.(type) {
|
||||||
case int:
|
case int:
|
||||||
itm.val = itm.val.(int) - 1
|
itm.val = val - 1
|
||||||
case int64:
|
case int64:
|
||||||
itm.val = itm.val.(int64) - 1
|
itm.val = val - 1
|
||||||
case int32:
|
case int32:
|
||||||
itm.val = itm.val.(int32) - 1
|
itm.val = val - 1
|
||||||
case uint:
|
case uint:
|
||||||
if itm.val.(uint) > 0 {
|
if val > 0 {
|
||||||
itm.val = itm.val.(uint) - 1
|
itm.val = val - 1
|
||||||
} else {
|
} else {
|
||||||
return errors.New("item val is less than 0")
|
return errors.New("item val is less than 0")
|
||||||
}
|
}
|
||||||
case uint32:
|
case uint32:
|
||||||
if itm.val.(uint32) > 0 {
|
if val > 0 {
|
||||||
itm.val = itm.val.(uint32) - 1
|
itm.val = val - 1
|
||||||
} else {
|
} else {
|
||||||
return errors.New("item val is less than 0")
|
return errors.New("item val is less than 0")
|
||||||
}
|
}
|
||||||
case uint64:
|
case uint64:
|
||||||
if itm.val.(uint64) > 0 {
|
if val > 0 {
|
||||||
itm.val = itm.val.(uint64) - 1
|
itm.val = val - 1
|
||||||
} else {
|
} else {
|
||||||
return errors.New("item val is less than 0")
|
return errors.New("item val is less than 0")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user