This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
version.go
134 lines (115 loc) · 4.91 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2017 Monax Industries Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package version
// version provides the current burrow version and a VersionIdentifier
// for the modules to identify their version with.
import (
"fmt"
)
// IMPORTANT: this version number needs to be manually kept
// in sync at the bottom of this file for the deployment scripts to parse
// the version number.
const (
// Client identifier to advertise over the network
clientIdentifier = "burrow"
// Major version component of the current release
versionMajor = 0
// Minor version component of the current release
versionMinor = 17
// Patch version component of the current release
versionPatch = 1
)
var burrowVersion *VersionIdentifier
func init() {
burrowVersion = New(clientIdentifier, versionMajor, versionMinor, versionPatch)
}
func GetBurrowVersion() *VersionIdentifier {
return burrowVersion
}
//------------------------------------------------------------------------------
// versioning globally for burrow and scoped for modules
type VersionIdentifier struct {
ClientIdentifier string
MajorVersion uint8
MinorVersion uint8
PatchVersion uint8
}
func New(client string, major, minor, patch uint8) *VersionIdentifier {
return &VersionIdentifier{
ClientIdentifier: client,
MajorVersion: major,
MinorVersion: minor,
PatchVersion: patch,
}
}
// GetVersionString returns `client-major.minor.patch` for burrow
// without a receiver, or for the version called on.
// MakeVersionString builds the same version string with provided parameters.
func GetVersionString() string { return burrowVersion.GetVersionString() }
func (v *VersionIdentifier) GetVersionString() string {
return fmt.Sprintf("%s-%d.%d.%d", v.ClientIdentifier, v.MajorVersion,
v.MinorVersion, v.PatchVersion)
}
// note: the arguments are passed in as int (rather than uint8)
// because on asserting the version constructed from the configuration file
// the casting of an int to uint8 is uglier than expanding the type range here.
// Should the configuration file have an invalid integer (that could not convert)
// then this will equally be reflected in a failed assertion of the version string.
func MakeVersionString(client string, major, minor, patch int) string {
return fmt.Sprintf("%s-%d.%d.%d", client, major, minor, patch)
}
// GetMinorVersionString returns `client-major.minor` for burrow
// without a receiver, or for the version called on.
// MakeMinorVersionString builds the same version string with
// provided parameters.
func GetMinorVersionString() string { return burrowVersion.GetVersionString() }
func (v *VersionIdentifier) GetMinorVersionString() string {
return fmt.Sprintf("%s-%d.%d", v.ClientIdentifier, v.MajorVersion,
v.MinorVersion)
}
// Return the plain version string without the ClientIdentifier
func GetSemanticVersionString() string { return burrowVersion.GetSemanticVersionString() }
func (v *VersionIdentifier) GetSemanticVersionString() string {
return fmt.Sprintf("%d.%d.%d", v.MajorVersion,
v.MinorVersion, v.PatchVersion)
}
// note: similar remark applies here on the use of `int` over `uint8`
// for the arguments as above for MakeVersionString()
func MakeMinorVersionString(client string, major, minor, patch int) string {
return fmt.Sprintf("%s-%d.%d", client, major, minor)
}
// GetVersion returns a tuple of client, major, minor, and patch as types,
// either for burrow without a receiver or the called version structure.
func GetVersion() (client string, major, minor, patch uint8) {
return burrowVersion.GetVersion()
}
func (version *VersionIdentifier) GetVersion() (
client string, major, minor, patch uint8) {
return version.ClientIdentifier, version.MajorVersion, version.MinorVersion,
version.PatchVersion
}
//------------------------------------------------------------------------------
// Matching functions
// MatchesMinorVersion matches the client identifier, major and minor version
// number of the reference version identifier to be equal with the receivers.
func MatchesMinorVersion(referenceVersion *VersionIdentifier) bool {
return burrowVersion.MatchesMinorVersion(referenceVersion)
}
func (version *VersionIdentifier) MatchesMinorVersion(
referenceVersion *VersionIdentifier) bool {
referenceClient, referenceMajor, referenceMinor, _ := referenceVersion.GetVersion()
return version.ClientIdentifier == referenceClient &&
version.MajorVersion == referenceMajor &&
version.MinorVersion == referenceMinor
}