Files
cloudpods/vendor/github.com/jaypipes/ghw/pkg/unitutil/unit.go
Zexi Li b5d8522f37 feat(region,host): server cpuset supported (#13527)
* feat(region,host): server cpuset supported

* feat(region,host): cpuset remove
2022-02-23 16:07:01 +08:00

38 lines
775 B
Go

//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package unitutil
var (
KB int64 = 1024
MB = KB * 1024
GB = MB * 1024
TB = GB * 1024
PB = TB * 1024
EB = PB * 1024
)
// AmountString returns a string representation of the amount with an amount
// suffix corresponding to the nearest kibibit.
//
// For example, AmountString(1022) == "1022). AmountString(1024) == "1KB", etc
func AmountString(size int64) (int64, string) {
switch {
case size < MB:
return KB, "KB"
case size < GB:
return MB, "MB"
case size < TB:
return GB, "GB"
case size < PB:
return TB, "TB"
case size < EB:
return PB, "PB"
default:
return EB, "EB"
}
}