Skip to content

Commit

Permalink
fix: Provide more meaningful default version info
Browse files Browse the repository at this point in the history
This change allows the version info to be inferred at build time to the best
extent possible.

If buildTime is omitted, it will default to the current time.
If the gitCommit is omitted, it will default to "unspecified", indicating that
this was not passed by an LD flag. The docs reflect how to properly set this
flag.
  • Loading branch information
dalehamel authored and leodido committed Aug 11, 2021
1 parent d4ef70b commit 205d3e4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ var versionFormat = "git commit: %s\nbuild date: %s"

// GitCommit returns the git commit
func GitCommit() string {
if gitCommit == "" {
gitCommit = "unspecified"
}
return gitCommit
}

// Time returns the build time
func Time() *time.Time {
now := time.Now()
if len(buildTime) == 0 {
return nil
return &now
}
i, err := strconv.ParseInt(buildTime, 10, 64)
if err != nil {
return nil
return &now
}
t := time.Unix(i, 0)
return &t
Expand Down

0 comments on commit 205d3e4

Please sign in to comment.