优化代码

This commit is contained in:
GoEdgeLab
2024-04-15 19:37:38 +08:00
parent 8ac6a421c0
commit 4f66f55152
8 changed files with 17 additions and 46 deletions

View File

@@ -282,14 +282,14 @@ func (this *APIStream) handleStatCache(message *pb.NodeStreamMessage) error {
}
sizeFormat := ""
if stat.Size < 1024 {
if stat.Size < (1 << 10) {
sizeFormat = strconv.FormatInt(stat.Size, 10) + " Bytes"
} else if stat.Size < 1024*1024 {
sizeFormat = fmt.Sprintf("%.2f KB", float64(stat.Size)/1024)
} else if stat.Size < 1024*1024*1024 {
sizeFormat = fmt.Sprintf("%.2f MB", float64(stat.Size)/1024/1024)
} else if stat.Size < (1 << 20) {
sizeFormat = fmt.Sprintf("%.2f KiB", float64(stat.Size)/(1<<10))
} else if stat.Size < (1 << 30) {
sizeFormat = fmt.Sprintf("%.2f MiB", float64(stat.Size)/(1<<20))
} else {
sizeFormat = fmt.Sprintf("%.2f GB", float64(stat.Size)/1024/1024/1024)
sizeFormat = fmt.Sprintf("%.2f GiB", float64(stat.Size)/(1<<30))
}
this.replyOk(message.RequestId, "size:"+sizeFormat+", count:"+strconv.Itoa(stat.Count))