-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
51 lines (39 loc) · 1013 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
50
51
package versions
import (
"fmt"
"time"
)
type Version struct {
Id int `json:"id"`
Major string `json:"major"`
Minor string `json:"minor"`
Revision string `json:"revision"`
ApplicationId string `json:"application_id"`
Name string `json:"name"`
Stable bool `json:"stable"`
Downloads []Download `json:"downloads"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
func (v *Version) Full() string {
return fmt.Sprintf("%s.%s.%s", v.Major, v.Minor, v.Revision)
}
// Validate confirms the Version is sufficient for entry into the store
// returns:
// - valid/ok (bool)
// - error (error)
func (v *Version) Validate() (bool, error) {
if v.ApplicationId == "" {
return false, ErrVersionMissingApplicationId
}
if v.Major == "" && v.Minor == "" && v.Revision == "" {
return false, ErrVersionMissingComponents
}
if v.Revision == "" {
v.Revision = "0"
}
if v.Name == "" {
v.Name = v.Full()
}
return true, nil
}