readysite / website / internal / helpers / format.go
476 B
format.go
package helpers

import "fmt"

const (
	KB = 1024
	MB = KB * 1024
	GB = MB * 1024
)

// FormatBytes formats a byte count as a human-readable string (KB, MB, GB).
func FormatBytes(bytes int64) string {
	switch {
	case bytes >= GB:
		return fmt.Sprintf("%.1f GB", float64(bytes)/GB)
	case bytes >= MB:
		return fmt.Sprintf("%.1f MB", float64(bytes)/MB)
	case bytes >= KB:
		return fmt.Sprintf("%.1f KB", float64(bytes)/KB)
	default:
		return fmt.Sprintf("%d bytes", bytes)
	}
}
← Back