Browse code

pkg/units: Unit constants directly int64

int64 seems sufficient

Docker-DCO-1.1-Signed-off-by: Francisco Carriedo <fcarriedo@gmail.com> (github: fcarriedo)

Francisco Carriedo authored on 2014/07/27 11:44:23
Showing 1 changed files
... ...
@@ -7,26 +7,24 @@ import (
7 7
 	"strings"
8 8
 )
9 9
 
10
-type unit int64
11
-
12 10
 // See: http://en.wikipedia.org/wiki/Binary_prefix
13 11
 const (
14 12
 	// Decimal
15
-	KB unit = 1000
16
-	MB      = 1000 * KB
17
-	GB      = 1000 * MB
18
-	TB      = 1000 * GB
19
-	PB      = 1000 * TB
13
+	KB = 1000
14
+	MB = 1000 * KB
15
+	GB = 1000 * MB
16
+	TB = 1000 * GB
17
+	PB = 1000 * TB
20 18
 
21 19
 	// Binary
22
-	KiB unit = 1024
23
-	MiB      = 1024 * KiB
24
-	GiB      = 1024 * MiB
25
-	TiB      = 1024 * GiB
26
-	PiB      = 1024 * TiB
20
+	KiB = 1024
21
+	MiB = 1024 * KiB
22
+	GiB = 1024 * MiB
23
+	TiB = 1024 * GiB
24
+	PiB = 1024 * TiB
27 25
 )
28 26
 
29
-type unitMap map[string]unit
27
+type unitMap map[string]int64
30 28
 
31 29
 var (
32 30
 	decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
... ...
@@ -81,7 +79,7 @@ func parseSize(sizeStr string, uMap unitMap) (int64, error) {
81 81
 
82 82
 	unitPrefix := strings.ToLower(matches[2])
83 83
 	if mul, ok := uMap[unitPrefix]; ok {
84
-		size *= int64(mul)
84
+		size *= mul
85 85
 	}
86 86
 
87 87
 	return size, nil