remove ginext/mongoext (no-dep lib)
This commit is contained in:
16
langext/bytes.go
Normal file
16
langext/bytes.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package langext
|
||||
|
||||
import "fmt"
|
||||
|
||||
func FormatBytesToSI(b uint64) string {
|
||||
const unit = 1000
|
||||
if b < unit {
|
||||
return fmt.Sprintf("%d B", b)
|
||||
}
|
||||
div, exp := uint64(unit), 0
|
||||
for n := b / unit; n >= unit; n /= unit {
|
||||
div *= unit
|
||||
exp++
|
||||
}
|
||||
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
|
||||
}
|
Reference in New Issue
Block a user