From d50e18ab6dd3de96c4d48816ab53e8ba9b74cf17 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 14 Mar 2014 19:34:59 -0400 Subject: [PATCH] Clean code --- .gopmfile | 4 ++++ modules/base/tool.go | 50 +++++++++++++++++++++++++++++++++++++++++++ web.go | 51 +------------------------------------------- 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/.gopmfile b/.gopmfile index d878c9f131..2aea7ea584 100644 --- a/.gopmfile +++ b/.gopmfile @@ -12,6 +12,10 @@ github.com/dchest/scrypt= github.com/go-sql-driver/mysql= github.com/libgit2/git2go=commit:054268a63418b03892bfd4c6a509a0294660074b github.com/lunny/xorm= +github.com/speedata/gogit= github.com/Unknwon/goconfig= github.com/gogits/logs= +[res] +include=templates|public|conf + diff --git a/modules/base/tool.go b/modules/base/tool.go index 445833cebc..c7b907bee1 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -78,3 +78,53 @@ func TimeSince(then time.Time) string { } return then.String() } + +// Subtract deals with subtraction of all types of number. +func Subtract(left interface{}, right interface{}) interface{} { + var rleft, rright int64 + var fleft, fright float64 + var isInt bool = true + switch left.(type) { + case int: + rleft = int64(left.(int)) + case int8: + rleft = int64(left.(int8)) + case int16: + rleft = int64(left.(int16)) + case int32: + rleft = int64(left.(int32)) + case int64: + rleft = left.(int64) + case float32: + fleft = float64(left.(float32)) + isInt = false + case float64: + fleft = left.(float64) + isInt = false + } + + switch right.(type) { + case int: + rright = int64(right.(int)) + case int8: + rright = int64(right.(int8)) + case int16: + rright = int64(right.(int16)) + case int32: + rright = int64(right.(int32)) + case int64: + rright = right.(int64) + case float32: + fright = float64(left.(float32)) + isInt = false + case float64: + fleft = left.(float64) + isInt = false + } + + if isInt { + return rleft - rright + } else { + return fleft + float64(rleft) - (fright + float64(rright)) + } +} diff --git a/web.go b/web.go index c60a262b00..7d04fc60e8 100644 --- a/web.go +++ b/web.go @@ -33,55 +33,6 @@ gogs web`, Flags: []cli.Flag{}, } -func Subtract(left interface{}, right interface{}) interface{} { - var rleft, rright int64 - var fleft, fright float64 - var isInt bool = true - switch left.(type) { - case int: - rleft = int64(left.(int)) - case int8: - rleft = int64(left.(int8)) - case int16: - rleft = int64(left.(int16)) - case int32: - rleft = int64(left.(int32)) - case int64: - rleft = left.(int64) - case float32: - fleft = float64(left.(float32)) - isInt = false - case float64: - fleft = left.(float64) - isInt = false - } - - switch right.(type) { - case int: - rright = int64(right.(int)) - case int8: - rright = int64(right.(int8)) - case int16: - rright = int64(right.(int16)) - case int32: - rright = int64(right.(int32)) - case int64: - rright = right.(int64) - case float32: - fright = float64(left.(float32)) - isInt = false - case float64: - fleft = left.(float64) - isInt = false - } - - if isInt { - return rleft - rright - } else { - return fleft + float64(rleft) - (fright + float64(rright)) - } -} - var AppHelpers template.FuncMap = map[string]interface{}{ "AppName": func() string { return base.Cfg.MustValue("", "APP_NAME") @@ -90,7 +41,7 @@ var AppHelpers template.FuncMap = map[string]interface{}{ return APP_VER }, "TimeSince": base.TimeSince, - "Subtract": Subtract, + "Subtract": base.Subtract, } func runWeb(*cli.Context) {