-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
49 lines (43 loc) · 1006 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
package nxgo
import (
"strconv"
"strings"
"github.com/jaracil/ei"
"github.com/nayarsystems/nxgo/nxcore"
)
var Version = &nxcore.NxVersion{
Major: 1,
Minor: 8,
Patch: 1,
}
func isVersionCompatible(v *nxcore.NxVersion) bool {
if v == nil || v.String() == "0.0.0" {
return false
}
if v.Major != Version.Major {
return false
}
if v.Minor < Version.Minor {
return false
}
return true
}
func getNexusVersion(nc *nxcore.NexusConn) *nxcore.NxVersion {
res, err := nc.Version()
if err == nil {
return parseVersionString(ei.N(res).M("version").StringZ())
}
return parseVersionString("0.0.0")
}
func parseVersionString(v string) *nxcore.NxVersion {
if verspl := strings.Split(v, "."); len(verspl) == 3 {
if major, err := strconv.Atoi(verspl[0]); err == nil {
if minor, err := strconv.Atoi(verspl[1]); err == nil {
if patch, err := strconv.Atoi(verspl[2]); err == nil {
return &nxcore.NxVersion{major, minor, patch}
}
}
}
}
return &nxcore.NxVersion{0, 0, 0}
}