Fix version output when no version is injected (i.e: go install)

pull/177/head
James Mills 2 weeks ago
parent a42f9e85ec
commit 03c863c028
Signed by: prologic
GPG Key ID: AC4C014F1440EBD6
  1. 2
      doc.go
  2. 23
      version.go

@ -0,0 +1,2 @@
// Package saltyim is a secure, easy, self-hosted messaging
package saltyim

@ -6,28 +6,41 @@ import (
"strings"
)
const (
defaultVersion = "0.0.0"
defaultCommit = "HEAD"
defaultBuild = "0000-01-01:00:00+00:00"
)
var (
// Version is the tagged release version in the form <major>.<minor>.<patch>
// following semantic versioning and is overwritten by the build system.
Version = "0.0.0"
Version = defaultVersion
// Commit is the commit sha of the build (normally from Git) and is overwritten
// by the build system.
Commit = "HEAD"
Commit = defaultCommit
// Build is the date and time of the build as an RFC3339 formatted string
// and is overwritten by the build system.
Build = "0000-01-01:00:00+00:00"
Build = defaultBuild
)
// FullVersion display the full version and build
func FullVersion() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
if !isDefault {
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
}
if info, ok := debug.ReadBuildInfo(); ok {
sb.WriteString(fmt.Sprintf(" %s %s", info.Main.Version, info.GoVersion))
if isDefault {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
}
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
if info.Main.Sum != "" {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
}

Loading…
Cancel
Save