formatting for bytes
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
5868daa09e
commit
f3f3ca4f11
24
helpers.go
24
helpers.go
|
@ -115,3 +115,27 @@ func (c *Cluster) AddDroplet(uuid string, hostname string, cpus int, mem int) *D
|
|||
c.Droplets = append(c.Droplets, d)
|
||||
return d
|
||||
}
|
||||
|
||||
func FormatBytes(b int64) string {
|
||||
if b < 2000 {
|
||||
return fmt.Sprintf("%d B", b)
|
||||
}
|
||||
|
||||
kb := int(b / 1024)
|
||||
if kb < 2000 {
|
||||
return fmt.Sprintf("%d KB", kb)
|
||||
}
|
||||
|
||||
mb := int(b / (1024 * 1024))
|
||||
if mb < 2000 {
|
||||
return fmt.Sprintf("%d MB", mb)
|
||||
}
|
||||
|
||||
gb := int(b / (1024 * 1024 * 1024))
|
||||
if gb < 2000 {
|
||||
return fmt.Sprintf("%d GB", gb)
|
||||
}
|
||||
|
||||
tb := int(b / (1024 * 1024 * 1024 * 1024))
|
||||
return fmt.Sprintf("%d TB", tb)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue