From 9a92980103fe66fc069665d94b952845d2239cce Mon Sep 17 00:00:00 2001 From: Tom Parker Date: Sun, 1 Sep 2024 09:29:09 -0400 Subject: [PATCH] Make version dynamic --- internal/pkg/api/api.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/pkg/api/api.go b/internal/pkg/api/api.go index 45d72d4..94c125b 100644 --- a/internal/pkg/api/api.go +++ b/internal/pkg/api/api.go @@ -4,6 +4,7 @@ import ( "fmt" "log/slog" "net/http" + "runtime/debug" "strings" "time" @@ -18,6 +19,18 @@ import ( "github.com/pkg/errors" ) +var commit = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value + } + } + } + + return "" +}() + type API struct { SecretTTL time.Duration WebTTL time.Duration @@ -42,8 +55,7 @@ func New(config *config.Config) http.Handler { MessageFieldName: "message", TimeFieldFormat: time.RFC3339, Tags: map[string]string{ - "version": "v0.1.8", - "env": "prod", + "version": commit, }, QuietDownRoutes: []string{ "/",