package master_ui
import (
"fmt"
"html/template"
"strconv"
"strings"
)
func bytesToHumanReadble(b uint64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := uint64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.2f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}
func percentFrom(total uint64, part_of uint64) string {
return fmt.Sprintf("%.2f", (float64(part_of)/float64(total))*100)
}
func join(data []int64) string {
var ret []string
for _, d := range data {
ret = append(ret, strconv.Itoa(int(d)))
}
return strings.Join(ret, ",")
}
var funcMap = template.FuncMap{
"join": join,
"bytesToHumanReadble": bytesToHumanReadble,
"percentFrom": percentFrom,
}
var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`