-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
41 lines (36 loc) · 997 Bytes
/
cache.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
package main
// Cache is an object that stores information about the latest version
type Cache struct {
Version *Version
CommitID string
}
// CreateCache creates Cache instance
func CreateCache(path string) (*Cache, error) {
version, commitID := GetDataFromHistory(path)
cache := Cache{Version: version, CommitID: commitID}
return &cache, nil
}
// GetDataFromHistory returns Version object and commitid from the history line
func GetDataFromHistory(path string) (*Version, string) {
var version Version
versionLine, err := ReadLastLine(path)
if err != nil {
return &version, ""
}
versionStr, err := ExtractVersionFromString(&versionLine)
if err != nil {
return &version, ""
}
versionList, err := SplitVersion(versionStr)
if err != nil {
return &version, ""
}
commitID, err := GetCommitID(&versionLine)
if err != nil {
return &version, ""
}
version.Major = versionList[0]
version.Minor = versionList[1]
version.Patch = versionList[2]
return &version, commitID
}