Skip to content

Commit 4b162aa

Browse files
committed
Add a -version switch to print git commit
1 parent cd45174 commit 4b162aa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

backend/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package main
22

33
import (
44
"errors"
5+
"fmt"
56
"log"
67
"os"
78
"os/signal"
9+
"runtime/debug"
810
"syscall"
911
)
1012

@@ -14,6 +16,7 @@ const (
1416
LOCAL RunType = iota
1517
WORKER
1618
SERVER
19+
UTIL_VERSION
1720
)
1821

1922
func ParseType(args []string) (RunType, []string) {
@@ -30,6 +33,9 @@ func ParseType(args []string) (RunType, []string) {
3033
case "-local":
3134
t = LOCAL
3235
continue
36+
case "-version":
37+
t = UTIL_VERSION
38+
continue
3339
}
3440

3541
resArgs = append(resArgs, arg)
@@ -59,6 +65,26 @@ func ParseConfigName(args []string) (string, []string) {
5965

6066
func main() {
6167
t, args := ParseType(os.Args[1:])
68+
69+
if t == UTIL_VERSION {
70+
info, ok := debug.ReadBuildInfo()
71+
if !ok {
72+
fmt.Println("unknown")
73+
return
74+
}
75+
for _, kv := range info.Settings {
76+
if kv.Value == "" {
77+
continue
78+
}
79+
switch kv.Key {
80+
case "vcs.revision":
81+
fmt.Println(kv.Value)
82+
return
83+
}
84+
}
85+
return
86+
}
87+
6288
configFile, args := ParseConfigName(args)
6389

6490
var config ConfigRoot

0 commit comments

Comments
 (0)