pkg/units: Using 'case' instead of trickled ifs

Seems the perfect case for 'case' ;).

Docker-DCO-1.1-Signed-off-by: Francisco Carriedo <fcarriedo@gmail.com> (github: fcarriedo)
This commit is contained in:
Francisco Carriedo 2014-07-22 00:38:47 -07:00
parent bb6217c055
commit 03697f0a93
1 changed files with 11 additions and 9 deletions

View File

@ -42,15 +42,16 @@ func FromHumanSize(size string) (int64, error) {
unit := strings.ToLower(matches[2])
if unit == "k" {
switch unit {
case "k":
theSize *= 1000
} else if unit == "m" {
case "m":
theSize *= 1000 * 1000
} else if unit == "g" {
case "g":
theSize *= 1000 * 1000 * 1000
} else if unit == "t" {
case "t":
theSize *= 1000 * 1000 * 1000 * 1000
} else if unit == "p" {
case "p":
theSize *= 1000 * 1000 * 1000 * 1000 * 1000
}
@ -80,13 +81,14 @@ func RAMInBytes(size string) (int64, error) {
unit := strings.ToLower(matches[2])
if unit == "k" {
switch unit {
case "k":
memLimit *= 1024
} else if unit == "m" {
case "m":
memLimit *= 1024 * 1024
} else if unit == "g" {
case "g":
memLimit *= 1024 * 1024 * 1024
} else if unit == "t" {
case "t":
memLimit *= 1024 * 1024 * 1024 * 1024
}