-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
52 lines (44 loc) · 953 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package version
import (
"strconv"
"strings"
)
type Version string
func (me Version) compareTo(other string) int {
var (
meTab = strings.Split(string(me), ".")
otherTab = strings.Split(other, ".")
)
for i, s := range meTab {
var meInt, otherInt int
meInt, _ = strconv.Atoi(s)
if len(otherTab) > i {
otherInt, _ = strconv.Atoi(otherTab[i])
}
if meInt > otherInt {
return 1
}
if otherInt > meInt {
return -1
}
}
if len(otherTab) > len(meTab) {
return -1
}
return 0
}
func (me Version) LessThan(other string) bool {
return me.compareTo(other) == -1
}
func (me Version) LessThanOrEqualTo(other string) bool {
return me.compareTo(other) <= 0
}
func (me Version) GreaterThan(other string) bool {
return me.compareTo(other) == 1
}
func (me Version) GreaterThanOrEqualTo(other string) bool {
return me.compareTo(other) >= 0
}
func (me Version) Equal(other string) bool {
return me.compareTo(other) == 0
}