Skip to content

Commit

Permalink
[Feature] Get version buildinfo
Browse files Browse the repository at this point in the history
package debug using ReadBuildInfo()

for relative version info

Signed-off-by: HyoBin Kim <[email protected]>
  • Loading branch information
Kim-Hyo-Bin committed Feb 16, 2024
1 parent a2cba11 commit 41a66be
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"strings"
"syscall"
"time"
Expand All @@ -21,10 +22,6 @@ import (
"go.containerssh.io/libcontainerssh/service"
)

var (
version = "0.5.0"
)

// Main is a helper function to start a standard ContainerSSH instance. It should be used as the outer-most function
// and should never be used as an embedding technique.
func Main() {
Expand Down Expand Up @@ -326,8 +323,18 @@ func healthCheck(cfg config.AppConfig, logger log.Logger) error {

func printVersion(writer io.Writer) error {
var buffer bytes.Buffer
buffer.WriteString("v")
buffer.WriteString(version)
var libcontainersshVersion string
bi, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Errorf("read build info %t", ok)
}
for _, dep := range bi.Deps {
if dep.Path == "go.containerssh.io/libcontainerssh" {
libcontainersshVersion = dep.Version
}
}
buffer.WriteString("libcontainerssh version ")
buffer.WriteString(libcontainersshVersion)
buffer.WriteString("\n")
if _, err := writer.Write(buffer.Bytes()); err != nil {
return fmt.Errorf("failed to write Version information (%w)", err)
Expand Down

0 comments on commit 41a66be

Please sign in to comment.