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