2015-01-06 14:36:56 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2017-01-31 05:28:00 +03:00
|
|
|
func formatBytes(i uint64) string {
|
2015-01-06 14:36:56 +03:00
|
|
|
switch {
|
|
|
|
case i > (1024 * 1024 * 1024 * 1024):
|
|
|
|
return fmt.Sprintf("%#.1fT", float64(i)/1024/1024/1024/1024)
|
|
|
|
case i > (1024 * 1024 * 1024):
|
|
|
|
return fmt.Sprintf("%#.1fG", float64(i)/1024/1024/1024)
|
|
|
|
case i > (1024 * 1024):
|
|
|
|
return fmt.Sprintf("%#.1fM", float64(i)/1024/1024)
|
|
|
|
case i > 1024:
|
|
|
|
return fmt.Sprintf("%#.1fK", float64(i)/1024)
|
|
|
|
default:
|
|
|
|
return fmt.Sprintf("%dB", i)
|
|
|
|
}
|
|
|
|
}
|