From 3f70299c36967bcea585208db9c188406d30c656 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Sun, 6 Aug 2023 22:01:25 +0300 Subject: [PATCH] Print version string on startup from git describe --- Makefile | 13 +++++++++++-- godoor.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 84d39f4..6d46028 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,13 @@ -dev: - GOOS=linux GOARCH=arm64 go build . +.PHONY: all build build_arm64 dev + +all: build + +build: + go build -ldflags="-X main.Version=`git describe --dirty`" . + +build_arm64: + GOOS=linux GOARCH=arm64 go build -ldflags="-X main.Version=`git describe --dirty`" . + +dev: build_arm64 scp godoor workshopdoor:/tmp/ ssh workshopdoor 'mv -f /tmp/godoor ~/ && sudo systemctl restart godoor' diff --git a/godoor.go b/godoor.go index b7e8e31..c742807 100644 --- a/godoor.go +++ b/godoor.go @@ -12,6 +12,7 @@ import ( "net/http" "os" "os/signal" + "runtime/debug" "strconv" "strings" "sync" @@ -67,6 +68,20 @@ type OpenedTimestamp struct { Closed *time.Time } +var Commit = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value + } + } + } + + return "" +}() + +var Version string + var config Config var globalLock sync.Mutex var validUids ValidUids @@ -78,6 +93,7 @@ var openDoorTimestamps []OpenedTimestamp func main() { + log.Printf("GoDoor ver: %s (%s)", Version, Commit) ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer cancel()