Browse code

pkg/version: lint and add comments

unclejack authored on 2014/10/07 00:41:53
Showing 1 changed files
... ...
@@ -5,53 +5,59 @@ import (
5 5
 	"strings"
6 6
 )
7 7
 
8
+// Version provides utility methods for comparing versions.
8 9
 type Version string
9 10
 
10
-func (me Version) compareTo(other Version) int {
11
+func (v Version) compareTo(other Version) int {
11 12
 	var (
12
-		meTab    = strings.Split(string(me), ".")
13
+		currTab  = strings.Split(string(v), ".")
13 14
 		otherTab = strings.Split(string(other), ".")
14 15
 	)
15 16
 
16
-	max := len(meTab)
17
+	max := len(currTab)
17 18
 	if len(otherTab) > max {
18 19
 		max = len(otherTab)
19 20
 	}
20 21
 	for i := 0; i < max; i++ {
21
-		var meInt, otherInt int
22
+		var currInt, otherInt int
22 23
 
23
-		if len(meTab) > i {
24
-			meInt, _ = strconv.Atoi(meTab[i])
24
+		if len(currTab) > i {
25
+			currInt, _ = strconv.Atoi(currTab[i])
25 26
 		}
26 27
 		if len(otherTab) > i {
27 28
 			otherInt, _ = strconv.Atoi(otherTab[i])
28 29
 		}
29
-		if meInt > otherInt {
30
+		if currInt > otherInt {
30 31
 			return 1
31 32
 		}
32
-		if otherInt > meInt {
33
+		if otherInt > currInt {
33 34
 			return -1
34 35
 		}
35 36
 	}
36 37
 	return 0
37 38
 }
38 39
 
39
-func (me Version) LessThan(other Version) bool {
40
-	return me.compareTo(other) == -1
40
+// LessThan checks if a version is less than another version
41
+func (v Version) LessThan(other Version) bool {
42
+	return v.compareTo(other) == -1
41 43
 }
42 44
 
43
-func (me Version) LessThanOrEqualTo(other Version) bool {
44
-	return me.compareTo(other) <= 0
45
+// LessThanOrEqualTo checks if a version is less than or equal to another
46
+func (v Version) LessThanOrEqualTo(other Version) bool {
47
+	return v.compareTo(other) <= 0
45 48
 }
46 49
 
47
-func (me Version) GreaterThan(other Version) bool {
48
-	return me.compareTo(other) == 1
50
+// GreaterThan checks if a version is greater than another one
51
+func (v Version) GreaterThan(other Version) bool {
52
+	return v.compareTo(other) == 1
49 53
 }
50 54
 
51
-func (me Version) GreaterThanOrEqualTo(other Version) bool {
52
-	return me.compareTo(other) >= 0
55
+// GreaterThanOrEqualTo checks ia version is greater than or equal to another
56
+func (v Version) GreaterThanOrEqualTo(other Version) bool {
57
+	return v.compareTo(other) >= 0
53 58
 }
54 59
 
55
-func (me Version) Equal(other Version) bool {
56
-	return me.compareTo(other) == 0
60
+// Equal checks if a version is equal to another
61
+func (v Version) Equal(other Version) bool {
62
+	return v.compareTo(other) == 0
57 63
 }