diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-12-22 23:33:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-22 15:33:19 +0000 |
commit | a163c53a606b0e40d709d8323056d00500f8135b (patch) | |
tree | 99985fd782d78291e294bd36dfa76fab709e7100 /modules/base/tool.go | |
parent | afe314fa772ccfa4bef51bafc91164844585dd01 (diff) | |
download | gitea-a163c53a606b0e40d709d8323056d00500f8135b.tar.gz gitea-a163c53a606b0e40d709d8323056d00500f8135b.zip |
Refactor template & test related code (#32938)
Move some legacy code from "base" package to proper packages.
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r-- | modules/base/tool.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go index 928c80700b..2303e64a68 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -13,9 +13,6 @@ import ( "errors" "fmt" "hash" - "os" - "path/filepath" - "runtime" "strconv" "strings" "time" @@ -189,49 +186,3 @@ func EntryIcon(entry *git.TreeEntry) string { return "file" } - -// SetupGiteaRoot Sets GITEA_ROOT if it is not already set and returns the value -func SetupGiteaRoot() string { - giteaRoot := os.Getenv("GITEA_ROOT") - if giteaRoot == "" { - _, filename, _, _ := runtime.Caller(0) - giteaRoot = strings.TrimSuffix(filename, "modules/base/tool.go") - wd, err := os.Getwd() - if err != nil { - rel, err := filepath.Rel(giteaRoot, wd) - if err != nil && strings.HasPrefix(filepath.ToSlash(rel), "../") { - giteaRoot = wd - } - } - if _, err := os.Stat(filepath.Join(giteaRoot, "gitea")); os.IsNotExist(err) { - giteaRoot = "" - } else if err := os.Setenv("GITEA_ROOT", giteaRoot); err != nil { - giteaRoot = "" - } - } - return giteaRoot -} - -// FormatNumberSI format a number -func FormatNumberSI(data any) string { - var num int64 - if num1, ok := data.(int64); ok { - num = num1 - } else if num1, ok := data.(int); ok { - num = int64(num1) - } else { - return "" - } - - if num < 1000 { - return fmt.Sprintf("%d", num) - } else if num < 1000000 { - num2 := float32(num) / float32(1000.0) - return fmt.Sprintf("%.1fk", num2) - } else if num < 1000000000 { - num2 := float32(num) / float32(1000000.0) - return fmt.Sprintf("%.1fM", num2) - } - num2 := float32(num) / float32(1000000000.0) - return fmt.Sprintf("%.1fG", num2) -} |