Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 41a66be

Browse files
committed
[Feature] Get version buildinfo
package debug using ReadBuildInfo() for relative version info Signed-off-by: HyoBin Kim <hb.kim@okestro.com>
1 parent a2cba11 commit 41a66be

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/signal"
1111
"path/filepath"
12+
"runtime/debug"
1213
"strings"
1314
"syscall"
1415
"time"
@@ -21,10 +22,6 @@ import (
2122
"go.containerssh.io/libcontainerssh/service"
2223
)
2324

24-
var (
25-
version = "0.5.0"
26-
)
27-
2825
// Main is a helper function to start a standard ContainerSSH instance. It should be used as the outer-most function
2926
// and should never be used as an embedding technique.
3027
func Main() {
@@ -326,8 +323,18 @@ func healthCheck(cfg config.AppConfig, logger log.Logger) error {
326323

327324
func printVersion(writer io.Writer) error {
328325
var buffer bytes.Buffer
329-
buffer.WriteString("v")
330-
buffer.WriteString(version)
326+
var libcontainersshVersion string
327+
bi, ok := debug.ReadBuildInfo()
328+
if !ok {
329+
return fmt.Errorf("read build info %t", ok)
330+
}
331+
for _, dep := range bi.Deps {
332+
if dep.Path == "go.containerssh.io/libcontainerssh" {
333+
libcontainersshVersion = dep.Version
334+
}
335+
}
336+
buffer.WriteString("libcontainerssh version ")
337+
buffer.WriteString(libcontainersshVersion)
331338
buffer.WriteString("\n")
332339
if _, err := writer.Write(buffer.Bytes()); err != nil {
333340
return fmt.Errorf("failed to write Version information (%w)", err)

0 commit comments

Comments
 (0)