Skip to content

Commit 620453e

Browse files
committed
git commit, version from runtime/debug
1 parent 85b1d8b commit 620453e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

mackerel-check.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99
"regexp"
1010
"runtime"
11+
"runtime/debug"
1112
"strings"
1213
)
1314

@@ -60,11 +61,25 @@ func run(args []string) int {
6061
return exitOK
6162
}
6263

63-
const version = "0.48.0"
64-
65-
var gitcommit string
64+
func fromVCS() (version, rev string) {
65+
version = "unknown"
66+
rev = "unknown"
67+
info, ok := debug.ReadBuildInfo()
68+
if !ok {
69+
return
70+
}
71+
version = info.Main.Version
72+
for _, s := range info.Settings {
73+
if s.Key == "vcs.revision" {
74+
rev = s.Value
75+
return
76+
}
77+
}
78+
return
79+
}
6680

6781
func printHelp() {
82+
version, gitcommit := fromVCS()
6883
fmt.Printf(`mackerel-check %s (rev %s) [%s %s %s]
6984
7085
Usage: mackerel-check <plugin> [<args>]

0 commit comments

Comments
 (0)