From 6f409bf0f109cdab9b10f41cf748205b2dafa15f Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 24 Jul 2024 00:53:20 -0700 Subject: [PATCH] fix version string maybe --- config/version.go | 18 ++++++++++++++++++ httpserver/templates.go | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 config/version.go diff --git a/config/version.go b/config/version.go new file mode 100644 index 0000000..61d8750 --- /dev/null +++ b/config/version.go @@ -0,0 +1,18 @@ +package config + +import ( + "runtime/debug" + + "github.com/sirupsen/logrus" +) + +var BuildInfo *debug.BuildInfo + +func init() { + var ok bool + BuildInfo, ok = debug.ReadBuildInfo() + if !ok { + logrus.Error("failed to read build info") + return + } +} diff --git a/httpserver/templates.go b/httpserver/templates.go index 2c413d3..8b189e2 100644 --- a/httpserver/templates.go +++ b/httpserver/templates.go @@ -2,10 +2,12 @@ package httpserver import ( "embed" + "fmt" "html/template" "io" "io/fs" + "git.janky.solutions/finn/go-project-template/config" echo "github.com/labstack/echo/v4" ) @@ -15,7 +17,9 @@ var ( templatesSubFS fs.FS allTemplates *template.Template funcs = template.FuncMap{ - "version": func() string { return "everybody v0.0.0 fakecommit" }, + "version": func() string { + return fmt.Sprintf("%s %s", config.BuildInfo.Main.Path, config.BuildInfo.Main.Version) + }, } //go:embed static