18 lines
421 B
Go
18 lines
421 B
Go
package utils
|
|
|
|
import "fmt"
|
|
|
|
// HumanReadableSize 转换为人类可读的文件大小
|
|
func HumanReadableSize(size uint64) string {
|
|
if size < 1024 {
|
|
return fmt.Sprintf("%d B", size)
|
|
}
|
|
if size < 1024*1024 {
|
|
return fmt.Sprintf("%.2f KB", float64(size)/1024)
|
|
}
|
|
if size < 1024*1024*1024 {
|
|
return fmt.Sprintf("%.2f MB", float64(size)/(1024*1024))
|
|
}
|
|
return fmt.Sprintf("%.2f GB", float64(size)/(1024*1024*1024))
|
|
}
|