mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 11:50:55 +00:00
Merge pull request #3502 from Quasilyte/patch-1
cache: remove excessive type assertions
This commit is contained in:
commit
7925458fc0
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