-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(all): add version to the daemons
This PR adds the version to the daemons. It infers the correct version from the git's latest tag.
- Loading branch information
Showing
8 changed files
with
95 additions
and
15 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
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
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,46 @@ | ||
package buildinfo | ||
|
||
import ( | ||
"runtime/debug" | ||
"strings" | ||
) | ||
|
||
const ( | ||
goOS = "GOOS" | ||
goArch = "GOARCH" | ||
vcsRevision = "vcs.revision" | ||
vcsTime = "vcs.time" | ||
) | ||
|
||
var version = "devel" | ||
|
||
type Info struct { | ||
*debug.BuildInfo | ||
settingsMap map[string]string | ||
|
||
Version string | ||
} | ||
|
||
func ReadVersionInfo() Info { | ||
info := Info{ | ||
Version: version, | ||
} | ||
if buildInfo, ok := debug.ReadBuildInfo(); ok { | ||
info.BuildInfo = buildInfo | ||
info.settingsMap = make(map[string]string, len(buildInfo.Settings)) | ||
for _, kv := range buildInfo.Settings { | ||
info.settingsMap[kv.Key] = kv.Value | ||
} | ||
} | ||
return info | ||
} | ||
|
||
func (info Info) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("Version: " + info.Version + "\n") | ||
sb.WriteString("Go Version: " + info.GoVersion + "\n") | ||
sb.WriteString("Git Commit: " + info.settingsMap[vcsRevision] + "\n") | ||
sb.WriteString("Built: " + info.settingsMap[vcsTime] + "\n") | ||
sb.WriteString("OS/Arch: " + info.settingsMap[goOS] + "/" + info.settingsMap[goArch]) | ||
return sb.String() | ||
} |