From d6b0062ae93beb0cedc35b81fc06630df09566ce Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:02:02 -0600 Subject: [PATCH] feat: set version flag (#632) Former-commit-id: 9edbda3daa7df20c2ba1df1fbddf0ecabfa3ee92 --- backend/app/api/main.go | 11 ++++++++++- backend/internal/sys/config/conf.go | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/app/api/main.go b/backend/app/api/main.go index 19258b0..5da695b 100644 --- a/backend/app/api/main.go +++ b/backend/app/api/main.go @@ -35,6 +35,15 @@ var ( buildTime = "now" ) +func build() string { + short := commit + if len(short) > 7 { + short = short[:7] + } + + return fmt.Sprintf("%s, commit %s, built at %s", version, short, buildTime) +} + // @title Homebox API // @version 1.0 // @description Track, Manage, and Organize your Things. @@ -47,7 +56,7 @@ var ( func main() { zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack - cfg, err := config.New() + cfg, err := config.New(build(), "Homebox inventory management system") if err != nil { panic(err) } diff --git a/backend/internal/sys/config/conf.go b/backend/internal/sys/config/conf.go index 932affe..28c278d 100644 --- a/backend/internal/sys/config/conf.go +++ b/backend/internal/sys/config/conf.go @@ -15,6 +15,7 @@ const ( ) type Config struct { + conf.Version Mode string `yaml:"mode" conf:"default:development"` // development or production Web WebConfig `yaml:"web"` Storage Storage `yaml:"storage"` @@ -46,10 +47,15 @@ type WebConfig struct { // New parses the CLI/Config file and returns a Config struct. If the file argument is an empty string, the // file is not read. If the file is not empty, the file is read and the Config struct is returned. -func New() (*Config, error) { +func New(buildstr string, description string) (*Config, error) { var cfg Config const prefix = "HBOX" + cfg.Version = conf.Version{ + Build: buildstr, + Desc: description, + } + help, err := conf.Parse(prefix, &cfg) if err != nil { if errors.Is(err, conf.ErrHelpWanted) {