-
Notifications
You must be signed in to change notification settings - Fork 667
/
version.go
58 lines (49 loc) · 1.07 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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package version
import (
"fmt"
"sync/atomic"
)
var (
// V1_0_0 is a useful version to use in tests
Semantic1_0_0 = &Semantic{
Major: 1,
Minor: 0,
Patch: 0,
}
_ fmt.Stringer = (*Semantic)(nil)
)
type Semantic struct {
Major int `json:"major" yaml:"major"`
Minor int `json:"minor" yaml:"minor"`
Patch int `json:"patch" yaml:"patch"`
str atomic.Value
}
// The only difference here between Semantic and Application is that Semantic
// prepends "v" rather than "avalanche/".
func (s *Semantic) String() string {
strIntf := s.str.Load()
if strIntf != nil {
return strIntf.(string)
}
str := fmt.Sprintf(
"v%d.%d.%d",
s.Major,
s.Minor,
s.Patch,
)
s.str.Store(str)
return str
}
// Compare returns a positive number if s > o, 0 if s == o, or a negative number
// if s < o.
func (s *Semantic) Compare(o *Semantic) int {
if s.Major != o.Major {
return s.Major - o.Major
}
if s.Minor != o.Minor {
return s.Minor - o.Minor
}
return s.Patch - o.Patch
}