From eb46ecfb71677e5e85ee71e195908ed7cd06c727 Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Thu, 7 Sep 2023 06:38:53 +0700 Subject: [PATCH] feat(*): add build{Date,Commit} --- Makefile | 5 ++++- main.go | 5 ++++- vars.go | 2 ++ www/index.html | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fbe2f7d..07c6c9e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ TELER_WAF_VERSION := $(shell go list -m -f '{{ .Version }}' github.com/kitabisa/teler-waf) +BUILD_DATE := $(shell date '+%D %T %Z') +BUILD_COMMIT := $(shell git rev-parse --short HEAD) + build: - go build -ldflags "-s -w -X 'main.telerWAFVersion=$(TELER_WAF_VERSION)'" -o playground . \ No newline at end of file + go build -ldflags "-s -w -X 'main.telerWAFVersion=$(TELER_WAF_VERSION)' -X 'main.buildDate=$(BUILD_DATE)' -X 'main.buildCommit=$(BUILD_COMMIT)'" -o playground . \ No newline at end of file diff --git a/main.go b/main.go index 9510d30..48132d9 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,9 @@ func init() { hostPort = net.JoinHostPort("0.0.0.0", port) meta = map[string]interface{}{ - "Version": telerWAFVersion, + "Version": telerWAFVersion, + "BuildDate": buildDate, + "BuildCommit": buildCommit, } } @@ -25,6 +27,7 @@ func main() { http.HandleFunc("/", indexHandler) http.HandleFunc("/api/play", playHandler) + log.Printf("teler-waf-playground %s (date: %s)\n", buildCommit, buildDate) log.Printf("teler-waf version %s\n", telerWAFVersion) log.Printf("Server started on http://%s\n", hostPort) if err := http.ListenAndServe(hostPort, nil); err != nil { diff --git a/vars.go b/vars.go index 1bc4e7f..b24cf73 100644 --- a/vars.go +++ b/vars.go @@ -5,6 +5,8 @@ var ( hostPort string telerWAFVersion string = "Unknown" + buildDate string = "Unknown" + buildCommit string = "Unknown" meta map[string]any ) diff --git a/www/index.html b/www/index.html index 23c7358..8502604 100644 --- a/www/index.html +++ b/www/index.html @@ -36,7 +36,6 @@

teler WAF Playground

-
> teler-waf version {{ .Version }}
@@ -139,6 +138,11 @@

teler WAF Playground

+
+
+> teler-waf version {{ .Version }}
+> build {{ .BuildCommit }} @ {{ .BuildDate }}
+