summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorOleg Kovalov <iamolegkovalov@gmail.com>2018-10-19 20:54:26 +0200
committertechknowlogick <hello@techknowlogick.com>2018-10-19 14:54:26 -0400
commit971dccda16f9541a4b38d3404e0b3e8e7b270490 (patch)
tree93ba2d3d744dec089abde066ebfe3f31d927fee8 /modules/base
parenta908b29a74ade0764f2c69b199e5f057abc902b6 (diff)
downloadgitea-971dccda16f9541a4b38d3404e0b3e8e7b270490.tar.gz
gitea-971dccda16f9541a4b38d3404e0b3e8e7b270490.zip
Use type switch (#5122)
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go32
-rw-r--r--modules/base/tool_test.go16
2 files changed, 24 insertions, 24 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index d5ec9e83fc..5b79a844ab 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -441,41 +441,41 @@ func Subtract(left interface{}, right interface{}) interface{} {
var rleft, rright int64
var fleft, fright float64
var isInt = true
- switch left.(type) {
+ switch left := left.(type) {
case int:
- rleft = int64(left.(int))
+ rleft = int64(left)
case int8:
- rleft = int64(left.(int8))
+ rleft = int64(left)
case int16:
- rleft = int64(left.(int16))
+ rleft = int64(left)
case int32:
- rleft = int64(left.(int32))
+ rleft = int64(left)
case int64:
- rleft = left.(int64)
+ rleft = left
case float32:
- fleft = float64(left.(float32))
+ fleft = float64(left)
isInt = false
case float64:
- fleft = left.(float64)
+ fleft = left
isInt = false
}
- switch right.(type) {
+ switch right := right.(type) {
case int:
- rright = int64(right.(int))
+ rright = int64(right)
case int8:
- rright = int64(right.(int8))
+ rright = int64(right)
case int16:
- rright = int64(right.(int16))
+ rright = int64(right)
case int32:
- rright = int64(right.(int32))
+ rright = int64(right)
case int64:
- rright = right.(int64)
+ rright = right
case float32:
- fright = float64(right.(float32))
+ fright = float64(right)
isInt = false
case float64:
- fright = right.(float64)
+ fright = right
isInt = false
}
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index f99edd5fbf..04cd682907 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -299,21 +299,21 @@ func TestFileSize(t *testing.T) {
func TestSubtract(t *testing.T) {
toFloat64 := func(n interface{}) float64 {
- switch n.(type) {
+ switch n := n.(type) {
case int:
- return float64(n.(int))
+ return float64(n)
case int8:
- return float64(n.(int8))
+ return float64(n)
case int16:
- return float64(n.(int16))
+ return float64(n)
case int32:
- return float64(n.(int32))
+ return float64(n)
case int64:
- return float64(n.(int64))
+ return float64(n)
case float32:
- return float64(n.(float32))
+ return float64(n)
case float64:
- return n.(float64)
+ return n
default:
return 0.0
}