summaryrefslogtreecommitdiff
path: root/utils/format/size.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-12-24 17:17:15 +0530
committerBobby <[email protected]>2025-12-24 17:17:15 +0530
commitd5ea2aa824eee4b7e2d169d21da0107d057e7bc6 (patch)
treee608fea8cf91d6915b7b6ce5eb46896dbdc2ad79 /utils/format/size.go
parentb77d75f05fb2059389c05f6c01484e0cd12e796e (diff)
downloadlain-d5ea2aa824eee4b7e2d169d21da0107d057e7bc6.tar.xz
lain-d5ea2aa824eee4b7e2d169d21da0107d057e7bc6.zip
feat: Implement API endpoints for email details and actions, and refactor email preview for client-side rendering with Shadow DOM.
Diffstat (limited to 'utils/format/size.go')
-rw-r--r--utils/format/size.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/utils/format/size.go b/utils/format/size.go
new file mode 100644
index 0000000..ce7c4fa
--- /dev/null
+++ b/utils/format/size.go
@@ -0,0 +1,16 @@
+package format
+
+import "fmt"
+
+func FormatFileSize(bytes int64) string {
+ const unit = 1024
+ if bytes < unit {
+ return fmt.Sprintf("%d B", bytes)
+ }
+ div, exp := int64(unit), 0
+ for n := bytes / unit; n >= unit; n /= unit {
+ div *= unit
+ exp++
+ }
+ return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
+}