aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-10-14 12:51:06 +0100
committerNeil Alexander <neilalexander@users.noreply.github.com>2020-10-14 12:51:06 +0100
commit286dd408ae623b218f9c5a97d53f174c0ea19cc2 (patch)
tree3dd4be2ddc51871858969ad82b2bb598fe6fafe2 /internal
parent7a1fd123debad64bf806503d519efa7bf3c85066 (diff)
Better semver compliance for version reporting
Diffstat (limited to 'internal')
-rw-r--r--internal/version.go28
1 files changed, 22 insertions, 6 deletions
diff --git a/internal/version.go b/internal/version.go
index 2ffd7c90..a9e245d4 100644
--- a/internal/version.go
+++ b/internal/version.go
@@ -1,6 +1,12 @@
package internal
-import "fmt"
+import (
+ "fmt"
+ "strings"
+)
+
+// the final version string
+var version string
// -ldflags "-X github.com/matrix-org/dendrite/internal.branch=master"
var branch string
@@ -16,12 +22,22 @@ const (
)
func VersionString() string {
- version := fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionTag)
- if branch != "" {
- version += fmt.Sprintf("-%s", branch)
+ return version
+}
+
+func init() {
+ version = fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
+ if VersionTag != "" {
+ version += "-" + VersionTag
}
+ parts := []string{}
if build != "" {
- version += fmt.Sprintf("+%s", build)
+ parts = append(parts, build)
+ }
+ if branch != "" {
+ parts = append(parts, branch)
+ }
+ if len(parts) > 0 {
+ version += "+" + strings.Join(parts, ".")
}
- return version
}