summaryrefslogtreecommitdiff
path: root/helpers.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-23 07:18:20 -0500
committerJeff Carr <[email protected]>2024-10-23 07:18:20 -0500
commitf3f3ca4f1194c46099ac2378af5c4176968f2b34 (patch)
tree4116c36983f0b3191f24d86be0b98e50eb0ef519 /helpers.go
parent5868daa09ec40ec38ce0c54ca18132f11bbc3763 (diff)
formatting for bytes
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'helpers.go')
-rw-r--r--helpers.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/helpers.go b/helpers.go
index faef03e..8af3f60 100644
--- a/helpers.go
+++ b/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)
+}