diff --git a/internal/version.go b/internal/version.go index 2ffd7c90e..a9e245d44 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) - } - if build != "" { - version += fmt.Sprintf("+%s", build) - } return version } + +func init() { + version = fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch) + if VersionTag != "" { + version += "-" + VersionTag + } + parts := []string{} + if build != "" { + parts = append(parts, build) + } + if branch != "" { + parts = append(parts, branch) + } + if len(parts) > 0 { + version += "+" + strings.Join(parts, ".") + } +}