Skip to content

Commit

Permalink
[feature] add more buildinfo
Browse files Browse the repository at this point in the history
add more build info debug options
revision, goversion.. etc

Signed-off-by: HyoBin Kim <[email protected]>
  • Loading branch information
Kim-Hyo-Bin committed Feb 28, 2024
1 parent 41a66be commit 4d5d2dd
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,19 +323,34 @@ func healthCheck(cfg config.AppConfig, logger log.Logger) error {

func printVersion(writer io.Writer) error {
var buffer bytes.Buffer
var libcontainersshVersion string
var libcontainersshVersion, buildRevision, buildTime, buildArch, buildmodified string
bi, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Errorf("read build info %t", ok)
}
fmt.Printf("%+v\n", bi)
for _, dep := range bi.Deps {
if dep.Path == "go.containerssh.io/libcontainerssh" {
libcontainersshVersion = dep.Version
break
}
}
buffer.WriteString("libcontainerssh version ")
buffer.WriteString(libcontainersshVersion)
buffer.WriteString("\n")
for _, setting := range bi.Settings {
if setting.Key == "vcs.revision" {
buildRevision = setting.Value
} else if setting.Key == "vcs.time" {
buildTime = setting.Value
} else if setting.Key == "GOARCH" {
buildArch = setting.Value
} else if setting.Key == "modified" {
buildmodified = setting.Value
}
}
stringGolangVersion := bi.GoVersion + " - " + buildArch + "\n"
stringLibcontainersshVersion := fmt.Sprintf("libcontainerssh version : %s\n", libcontainersshVersion)
stringBuildRevision := fmt.Sprintf("build revision: %s(%s) {{%s}}\n", buildRevision, buildTime, buildmodified)
stringConcateBuildInfo := stringGolangVersion + stringLibcontainersshVersion + stringBuildRevision
buffer.WriteString(stringConcateBuildInfo)
if _, err := writer.Write(buffer.Bytes()); err != nil {
return fmt.Errorf("failed to write Version information (%w)", err)
}
Expand Down

0 comments on commit 4d5d2dd

Please sign in to comment.