common: define storage units as constants
Define all used storage units as constants. Use them in `DataSizeToUint64()`, instead of literal multiples.
This commit is contained in:
parent
b5d1c8866a
commit
ff28b0f5d3
2 changed files with 19 additions and 8 deletions
|
|
@ -65,14 +65,14 @@ func DataSizeToUint64(size string) (uint64, error) {
|
|||
re *regexp.Regexp
|
||||
multiple uint64
|
||||
}{
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*kB$`), 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*KiB$`), 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MB$`), 1000 * 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MiB$`), 1024 * 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GB$`), 1000 * 1000 * 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GiB$`), 1024 * 1024 * 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TB$`), 1000 * 1000 * 1000 * 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TiB$`), 1024 * 1024 * 1024 * 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*kB$`), KiloByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*KiB$`), KibiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MB$`), MegaByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MiB$`), MebiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GB$`), GigaByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GiB$`), GibiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TB$`), TeraByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TiB$`), TebiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+$`), 1},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue