Move version initializiation to init function to prevent race conditions (#1299)

This commit is contained in:
Elichai Turkel 2020-12-28 16:04:00 +02:00 committed by GitHub
parent c7c8b25c09
commit af1b8c8490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,7 @@ var appBuild string
var version = "" // string used for memoization of version var version = "" // string used for memoization of version
// Version returns the application version as a properly formed string func init() {
func Version() string {
if version == "" { if version == "" {
// Start with the major, minor, and patch versions. // Start with the major, minor, and patch versions.
version = fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch) version = fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
@ -35,7 +34,10 @@ func Version() string {
version = fmt.Sprintf("%s-%s", version, appBuild) version = fmt.Sprintf("%s-%s", version, appBuild)
} }
} }
}
// Version returns the application version as a properly formed string
func Version() string {
return version return version
} }