-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show version information based on build metadata
- Loading branch information
1 parent
0f70450
commit 5446fc7
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package config | ||
|
||
import ( | ||
"runtime/debug" | ||
"strings" | ||
) | ||
|
||
func VersionString() string { | ||
version := "v0.0.0-unknown" | ||
if info, ok := debug.ReadBuildInfo(); ok { | ||
for _, s := range info.Settings { | ||
switch s.Key { | ||
case "-tags": | ||
for _, t := range strings.Split(s.Value, ",") { | ||
if len(t) > 0 && t[0] == 'v' { | ||
return t | ||
} | ||
} | ||
case "vcs": | ||
version = s.Value | ||
case "vcs.revision": | ||
if version == "git" && len(s.Value) >= 10 { | ||
version += "-" + s.Value[:10] | ||
} | ||
case "vcs.modified": | ||
if s.Value == "true" { | ||
return (version + "-modified") | ||
} | ||
} | ||
} | ||
} | ||
return version | ||
} |