format bytes
This commit is contained in:
parent
f91bb2f7f0
commit
9f04e5a8ea
1 changed files with 3 additions and 0 deletions
|
@ -7,10 +7,13 @@ const (
|
||||||
KiloByte = Byte * 1000
|
KiloByte = Byte * 1000
|
||||||
MegaByte = KiloByte * 1000
|
MegaByte = KiloByte * 1000
|
||||||
GigaByte = MegaByte * 1000
|
GigaByte = MegaByte * 1000
|
||||||
|
TeraByte = GigaByte * 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
func HumanBytes(b int64) string {
|
func HumanBytes(b int64) string {
|
||||||
switch {
|
switch {
|
||||||
|
case b > TeraByte:
|
||||||
|
return fmt.Sprintf("%.1f TB", float64(b)/TeraByte)
|
||||||
case b > GigaByte:
|
case b > GigaByte:
|
||||||
return fmt.Sprintf("%.1f GB", float64(b)/GigaByte)
|
return fmt.Sprintf("%.1f GB", float64(b)/GigaByte)
|
||||||
case b > MegaByte:
|
case b > MegaByte:
|
||||||
|
|
Loading…
Reference in a new issue