Print version string on startup from git describe
This commit is contained in:
parent
fddac32cc7
commit
3f70299c36
13
Makefile
13
Makefile
@ -1,4 +1,13 @@
|
|||||||
dev:
|
.PHONY: all build build_arm64 dev
|
||||||
GOOS=linux GOARCH=arm64 go build .
|
|
||||||
|
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/
|
scp godoor workshopdoor:/tmp/
|
||||||
ssh workshopdoor 'mv -f /tmp/godoor ~/ && sudo systemctl restart godoor'
|
ssh workshopdoor 'mv -f /tmp/godoor ~/ && sudo systemctl restart godoor'
|
||||||
|
16
godoor.go
16
godoor.go
@ -12,6 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -67,6 +68,20 @@ type OpenedTimestamp struct {
|
|||||||
Closed *time.Time
|
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 config Config
|
||||||
var globalLock sync.Mutex
|
var globalLock sync.Mutex
|
||||||
var validUids ValidUids
|
var validUids ValidUids
|
||||||
@ -78,6 +93,7 @@ var openDoorTimestamps []OpenedTimestamp
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
log.Printf("GoDoor ver: %s (%s)", Version, Commit)
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user