forked from zurvan-lab/timetrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
48 lines (39 loc) · 903 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
package timetracedb
import (
"encoding/json"
"encoding/xml"
"fmt"
)
// These constants follow the semantic versioning 2.0.0 spec (http://semver.org/)
type Version struct {
Meta string `json:"meta" xml:"meta"`
Major uint8 `json:"major" xml:"major"`
Minor uint8 `json:"minor" xml:"minor"`
Patch uint8 `json:"patch" xml:"patch"`
}
var version = Version{
Meta: "beta",
Major: 0,
Minor: 1,
Patch: 0,
}
func Agent() string {
return fmt.Sprintf("timetrace %s", StringVersion())
}
func StringVersion() string {
return fmt.Sprintf("%d.%d.%d-%s", version.Major, version.Minor, version.Patch, version.Meta)
}
func JSONVersion() (string, error) {
v, err := json.Marshal(version)
if err != nil {
return "", err
}
return string(v), nil
}
func XMLVersion() (string, error) {
v, err := xml.MarshalIndent(version, "", " ")
if err != nil {
return "", err
}
return string(v), nil
}