From 299020949f5b476459ac4dca2a01ada3fb7eb5de Mon Sep 17 00:00:00 2001 From: Francisco Carriedo Date: Tue, 22 Jul 2014 00:38:47 -0700 Subject: [PATCH] pkg/units: Using 'case' instead of trickled ifs Seems the perfect case for 'case' ;). Docker-DCO-1.1-Signed-off-by: Francisco Carriedo (github: fcarriedo) --- units/size.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/units/size.go b/units/size.go index e6e9f21..d8410b4 100644 --- a/units/size.go +++ b/units/size.go @@ -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 }