From 804ea3b58ea9f9278f81a6b78841ca7461058d20 Mon Sep 17 00:00:00 2001 From: Francisco Carriedo Date: Sat, 26 Jul 2014 19:44:23 -0700 Subject: [PATCH] pkg/units: Unit constants directly int64 int64 seems sufficient Docker-DCO-1.1-Signed-off-by: Francisco Carriedo (github: fcarriedo) --- units/size.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/units/size.go b/units/size.go index f04785e..88d91dd 100644 --- a/units/size.go +++ b/units/size.go @@ -7,26 +7,24 @@ import ( "strings" ) -type unit int64 - // See: http://en.wikipedia.org/wiki/Binary_prefix const ( // Decimal - KB unit = 1000 - MB = 1000 * KB - GB = 1000 * MB - TB = 1000 * GB - PB = 1000 * TB + KB = 1000 + MB = 1000 * KB + GB = 1000 * MB + TB = 1000 * GB + PB = 1000 * TB // Binary - KiB unit = 1024 - MiB = 1024 * KiB - GiB = 1024 * MiB - TiB = 1024 * GiB - PiB = 1024 * TiB + KiB = 1024 + MiB = 1024 * KiB + GiB = 1024 * MiB + TiB = 1024 * GiB + PiB = 1024 * TiB ) -type unitMap map[string]unit +type unitMap map[string]int64 var ( decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB} @@ -81,7 +79,7 @@ func parseSize(sizeStr string, uMap unitMap) (int64, error) { unitPrefix := strings.ToLower(matches[2]) if mul, ok := uMap[unitPrefix]; ok { - size *= int64(mul) + size *= mul } return size, nil