From ca116ec0c931a0309ae745e8b102bcd2865468ae Mon Sep 17 00:00:00 2001 From: Eno Compton Date: Tue, 19 Apr 2022 09:45:30 -0600 Subject: [PATCH] feat: add support for metadata in version (#6) --- cmd/root.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index d03a6141..5486949c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,14 +37,26 @@ var ( // versionString indicates the version of this library. //go:embed version.txt versionString string - userAgent string + // metadataString indiciates additional build or distribution metadata. + metadataString string + userAgent string ) func init() { - versionString = strings.TrimSpace(versionString) + versionString = semanticVersion() userAgent = "alloy-db-auth-proxy/" + versionString } +// semanticVersion returns the version of the proxy including an compile-time +// metadata. +func semanticVersion() string { + v := strings.TrimSpace(versionString) + if metadataString != "" { + v += "+" + metadataString + } + return v +} + // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() {