Browse Source

#2225

add MB2GB
tags/v1.22.7.1
chenyifan01 3 years ago
parent
commit
581670cf37
1 changed files with 13 additions and 0 deletions
  1. +13
    -0
      modules/templates/helper.go

+ 13
- 0
modules/templates/helper.go View File

@@ -18,6 +18,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
texttmpl "text/template"
"time"
@@ -327,6 +328,7 @@ func NewFuncMap() []template.FuncMap {
},
"GetRefType": GetRefType,
"GetRefName": GetRefName,
"MB2GB": MB2GB,
}}
}

@@ -785,3 +787,14 @@ func GetRefName(ref string) string {
reg := regexp.MustCompile(REF_TYPE_PATTERN)
return reg.ReplaceAllString(ref, "")
}

func MB2GB(size int64) string {
s := strconv.FormatFloat(float64(size)/float64(1024), 'f', 2, 64)
for strings.HasSuffix(s, "0") {
s = strings.TrimSuffix(s, "0")
}
if strings.HasSuffix(s, ".") {
s = strings.TrimSuffix(s, ".")
}
return s
}

Loading…
Cancel
Save