bytes.go 313 B

12345678910111213141516
  1. package format
  2. import "fmt"
  3. func HumanBytes(b int64) string {
  4. switch {
  5. case b > 1000*1000*1000:
  6. return fmt.Sprintf("%d GB", b/1000/1000/1000)
  7. case b > 1000*1000:
  8. return fmt.Sprintf("%d MB", b/1000/1000)
  9. case b > 1000:
  10. return fmt.Sprintf("%d KB", b/1000)
  11. default:
  12. return fmt.Sprintf("%d B", b)
  13. }
  14. }