Browse code

pkg/units: Better to not use `error` as var name

Better to not use `error` as var name (might eclipse the error type) for
clarity and to prevent subtle bugs.

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

Francisco Carriedo authored on 2014/07/22 15:58:59
Showing 1 changed files
... ...
@@ -24,8 +24,8 @@ func HumanSize(size int64) string {
24 24
 // FromHumanSize returns an integer from a human-readable specification of a size
25 25
 // using SI standard (eg. "44kB", "17MB")
26 26
 func FromHumanSize(size string) (int64, error) {
27
-	re, error := regexp.Compile("^(\\d+)([kKmMgGtTpP])?[bB]?$")
28
-	if error != nil {
27
+	re, err := regexp.Compile("^(\\d+)([kKmMgGtTpP])?[bB]?$")
28
+	if err != nil {
29 29
 		return -1, fmt.Errorf("%s does not specify not a size", size)
30 30
 	}
31 31
 
... ...
@@ -35,9 +35,9 @@ func FromHumanSize(size string) (int64, error) {
35 35
 		return -1, fmt.Errorf("Invalid size: '%s'", size)
36 36
 	}
37 37
 
38
-	theSize, error := strconv.ParseInt(matches[1], 10, 0)
39
-	if error != nil {
40
-		return -1, error
38
+	theSize, err := strconv.ParseInt(matches[1], 10, 0)
39
+	if err != nil {
40
+		return -1, err
41 41
 	}
42 42
 
43 43
 	unit := strings.ToLower(matches[2])
... ...
@@ -62,9 +62,9 @@ func FromHumanSize(size string) (int64, error) {
62 62
 // returns the number of bytes, or -1 if the string is unparseable.
63 63
 // Units are case-insensitive, and the 'b' suffix is optional.
64 64
 func RAMInBytes(size string) (int64, error) {
65
-	re, error := regexp.Compile("^(\\d+)([kKmMgGtT])?[bB]?$")
66
-	if error != nil {
67
-		return -1, error
65
+	re, err := regexp.Compile("^(\\d+)([kKmMgGtT])?[bB]?$")
66
+	if err != nil {
67
+		return -1, err
68 68
 	}
69 69
 
70 70
 	matches := re.FindStringSubmatch(size)
... ...
@@ -73,9 +73,9 @@ func RAMInBytes(size string) (int64, error) {
73 73
 		return -1, fmt.Errorf("Invalid size: '%s'", size)
74 74
 	}
75 75
 
76
-	memLimit, error := strconv.ParseInt(matches[1], 10, 0)
77
-	if error != nil {
78
-		return -1, error
76
+	memLimit, err := strconv.ParseInt(matches[1], 10, 0)
77
+	if err != nil {
78
+		return -1, err
79 79
 	}
80 80
 
81 81
 	unit := strings.ToLower(matches[2])