update: HTTP API

This commit is contained in:
Oarkflow
2025-03-30 16:55:32 +05:45
parent ba75adc7d6
commit 31a9fb8ba7
11 changed files with 340 additions and 85 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"unsafe"
)
@@ -14,3 +15,17 @@ func FromByte(b []byte) string {
p := unsafe.SliceData(b)
return unsafe.String(p, len(b))
}
func FormatBytes(bytes int64) string {
units := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
if bytes == 0 {
return fmt.Sprintf("0 B")
}
size := float64(bytes)
unitIndex := 0
for size >= 1024 && unitIndex < len(units)-1 {
size /= 1024
unitIndex++
}
return fmt.Sprintf("%.2f %s", size, units[unitIndex])
}