-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathversion.go
80 lines (72 loc) · 2.08 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cobblerclient
type ExtendedVersion struct {
Gitdate string
Gitstamp string
Builddate string
Version string
VersionTuple []int
}
type CobblerVersion struct {
Major int
Minor int
Patch int
}
func (cv *CobblerVersion) GreaterThan(otherVersion *CobblerVersion) bool {
if cv.Equal(otherVersion) {
return false
}
if cv.Major > otherVersion.Major {
return true
}
if cv.Major == otherVersion.Major && cv.Minor > otherVersion.Minor {
return true
}
if cv.Major == otherVersion.Major && cv.Minor == otherVersion.Minor && cv.Patch > otherVersion.Patch {
return true
}
return false
}
func (cv *CobblerVersion) LessThan(otherVersion *CobblerVersion) bool {
if cv.Equal(otherVersion) {
return false
}
return !cv.GreaterThan(otherVersion)
}
func (cv *CobblerVersion) Equal(otherVersion *CobblerVersion) bool {
return cv.Major == otherVersion.Major && cv.Minor == otherVersion.Minor && cv.Patch == otherVersion.Patch
}
func (cv *CobblerVersion) NotEqual(otherVersion *CobblerVersion) bool {
return !cv.Equal(otherVersion)
}
// Version is a shorter and easier version representation. Normally you want to call [Client.ExtendedVersion].
func (c *Client) Version() (float64, error) {
res, err := c.Call("version")
if err != nil {
return 0, err
}
return res.(float64), err
}
// ExtendedVersion returns the version information of the server.
func (c *Client) ExtendedVersion() (ExtendedVersion, error) {
extendedVersion := ExtendedVersion{}
data, err := c.Call("extended_version")
if err != nil {
return extendedVersion, err
}
switch data.(type) {
case map[string]interface{}:
data := data.(map[string]interface{})
var versionTuple, err = returnIntSlice(data["version_tuple"], err)
if err != nil {
return extendedVersion, err
}
extendedVersion.Version = data["version"].(string)
extendedVersion.VersionTuple = versionTuple
extendedVersion.Builddate = data["builddate"].(string)
extendedVersion.Gitdate = data["gitdate"].(string)
extendedVersion.Gitstamp = data["gitstamp"].(string)
default:
return extendedVersion, err
}
return extendedVersion, err
}