MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / FormatByte

Function FormatByte

common/format.go:54–77  ·  view source on GitHub ↗
(b int64)

Source from the content-addressed store, hash-verified

52}
53
54func FormatByte(b int64) string {
55 const (
56 KB = 1000
57 MB = KB * 1000
58 GB = MB * 1000
59 TB = GB * 1000
60 PB = TB * 1000
61 )
62
63 switch {
64 case b < KB:
65 return fmt.Sprintf("%dB", b)
66 case b < MB:
67 return fmt.Sprintf("%.1fKB", float64(b)/KB)
68 case b < GB:
69 return fmt.Sprintf("%.1fMB", float64(b)/MB)
70 case b < TB:
71 return fmt.Sprintf("%.1fGB", float64(b)/GB)
72 case b < PB:
73 return fmt.Sprintf("%.1fTB", float64(b)/TB)
74 default:
75 return fmt.Sprintf("%.1fPB", float64(b)/PB)
76 }
77}

Callers 3

RestLogInfoMethod · 0.92
RestLogsMethod · 0.92
generateTopNFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected