Skip to content

Commit

Permalink
Print built date
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Oct 23, 2024
1 parent d5cac1a commit 065d00c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
builds:
- binary: triax-eoc-exporter
main: ./cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
log.Fatal(err.Error())
}

cfg.Start(*listenAddress, version)
cfg.Start(*listenAddress, version, date)
}

func initLogger(verbose bool) {
Expand Down
11 changes: 8 additions & 3 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})

Expand All @@ -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))
}

Expand Down Expand Up @@ -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(`<!doctype html>
Expand All @@ -134,7 +136,10 @@ var tmpl = template.Must(template.New("index").Option("missingkey=error").Parse(
</head>
<body>
<h1>Triax EoC Exporter</h1>
<p>Version: {{.Version}}</p>
<p>
Version: {{.Version}}<br>
Built at: {{.Date}}
</p>
<h2>Controllers</h2>
<p><a href="/controllers">List as JSON</a></p>
Expand Down

0 comments on commit 065d00c

Please sign in to comment.