-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion.go
66 lines (62 loc) · 1.06 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package go_i2cp
import (
"strconv"
"strings"
)
type Version struct {
major, minor, micro, qualifier uint16
version string
}
func parseVersion(str string) Version {
var v = Version{}
segments := strings.Split(str, ".")
n := len(segments)
if n > 0 {
i, _ := strconv.Atoi(segments[0])
v.major = uint16(i)
}
if n > 1 {
i, _ := strconv.Atoi(segments[1])
v.minor = uint16(i)
}
if n > 2 {
i, _ := strconv.Atoi(segments[2])
v.micro = uint16(i)
}
if n > 3 {
i, _ := strconv.Atoi(segments[3])
v.qualifier = uint16(i)
}
return v
}
func (v *Version) compare(other Version) int {
if v.major != other.major {
if (v.major - other.major) > 0 {
return 1
} else {
return -1
}
}
if v.minor != other.minor {
if (v.minor - other.minor) > 0 {
return 1
} else {
return -1
}
}
if v.micro != other.micro {
if (v.micro - other.micro) > 0 {
return 1
} else {
return -1
}
}
if v.qualifier != other.qualifier {
if (v.qualifier - other.qualifier) > 0 {
return 1
} else {
return -1
}
}
return 0
}