From 065d00c6e1e134850dc9dafc3f415ce908a7777c Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Wed, 23 Oct 2024 10:34:23 +0200 Subject: [PATCH] Print built date --- .goreleaser.yml | 1 + cmd/main.go | 2 +- exporter/exporter.go | 11 ++++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 163935a..ccacdb6 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,4 @@ +version: 2 builds: - binary: triax-eoc-exporter main: ./cmd diff --git a/cmd/main.go b/cmd/main.go index 3ddada8..18c4c40 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -51,7 +51,7 @@ func main() { log.Fatal(err.Error()) } - cfg.Start(*listenAddress, version) + cfg.Start(*listenAddress, version, date) } func initLogger(verbose bool) { diff --git a/exporter/exporter.go b/exporter/exporter.go index e46d724..21f631d 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -16,12 +16,13 @@ import ( _ "github.com/digineo/triax-eoc-exporter/backend/v3" ) -func (cfg *Config) Start(listenAddress, version string) { +func (cfg *Config) Start(listenAddress, version, date string) { router := httprouter.New() router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { tmpl.Execute(w, &indexVariables{ Controllers: cfg.Controllers, Version: version, + Date: date, }) }) @@ -30,7 +31,7 @@ func (cfg *Config) Start(listenAddress, version string) { router.GET("/controllers/:target/api/*path", cfg.targetMiddleware(cfg.apiHandler)) //router.PUT("/controllers/:target/nodes/:mac", cfg.targetMiddleware(cfg.updateNodeHandler)) - slog.Info("Starting exporter", "listenAddress", listenAddress) + slog.Info("Starting exporter", "listenAddress", listenAddress, "version", version, "builtDate", date) slog.Info("Server stopped", "reason", http.ListenAndServe(listenAddress, router)) } @@ -124,6 +125,7 @@ func (cfg *Config) apiHandler(client *client.Client, w http.ResponseWriter, r *h type indexVariables struct { Controllers []Controller Version string + Date string } var tmpl = template.Must(template.New("index").Option("missingkey=error").Parse(` @@ -134,7 +136,10 @@ var tmpl = template.Must(template.New("index").Option("missingkey=error").Parse(

Triax EoC Exporter

-

Version: {{.Version}}

+

+ Version: {{.Version}}
+ Built at: {{.Date}} +

Controllers

List as JSON