diff --git a/pkg/koyeb/renderer/format.go b/pkg/koyeb/renderer/format.go index e7886f16..8ada81eb 100644 --- a/pkg/koyeb/renderer/format.go +++ b/pkg/koyeb/renderer/format.go @@ -42,7 +42,37 @@ func FormatID(fullId string, full bool) string { return fullId[:8] } -func FormatSize(size int64) string { +type Size interface { + GetSize() int64 +} + +type ByteSize int64 + +func (b ByteSize) GetSize() int64 { + return int64(b) +} + +type KBSize int64 + +func (k KBSize) GetSize() int64 { + return int64(k) * 1024 +} + +type MBSize int64 + +func (m MBSize) GetSize() int64 { + return int64(m) * 1024 * 1024 +} + +type GBSize int64 + +func (g GBSize) GetSize() int64 { + return int64(g) * 1024 * 1024 * 1024 +} + +func FormatSize(sized Size) string { + size := sized.GetSize() + switch { case size > 1024*1024*1024: return fmt.Sprintf("%.2fG", float64(size)/1024/1024/1024) diff --git a/pkg/koyeb/volumes_get.go b/pkg/koyeb/volumes_get.go index 4ec40b1d..52b4bce7 100644 --- a/pkg/koyeb/volumes_get.go +++ b/pkg/koyeb/volumes_get.go @@ -65,7 +65,7 @@ func (r *GetVolumeReply) Fields() []map[string]string { "region": item.GetRegion(), "status": formatVolumeStatus(item.GetStatus()), "type": formatVolumeType(item.GetBackingStore()), - "size": renderer.FormatSize(item.GetMaxSize()), + "size": renderer.FormatSize(renderer.MBSize(item.GetMaxSize())), "read_only": fmt.Sprintf("%t", item.GetReadOnly()), "created_at": renderer.FormatTime(item.GetCreatedAt()), "updated_at": renderer.FormatTime(item.GetUpdatedAt()), diff --git a/pkg/koyeb/volumes_list.go b/pkg/koyeb/volumes_list.go index 3b693ce7..08ad078f 100644 --- a/pkg/koyeb/volumes_list.go +++ b/pkg/koyeb/volumes_list.go @@ -76,7 +76,7 @@ func (r *ListVolumesReply) Fields() []map[string]string { "region": item.GetRegion(), "status": formatVolumeStatus(item.GetStatus()), "type": formatVolumeType(item.GetBackingStore()), - "size": renderer.FormatSize(item.GetMaxSize()), + "size": renderer.FormatSize(renderer.MBSize(item.GetMaxSize())), "read_only": fmt.Sprintf("%t", item.GetReadOnly()), "created_at": renderer.FormatTime(item.GetCreatedAt()), "updated_at": renderer.FormatTime(item.GetUpdatedAt()),