Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
fix: use git version as user-agent (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclimse authored Nov 18, 2023
1 parent a6dff54 commit 1a0195e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions cmd/scwtui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ func main() {
}

rs := &RootState{
Config: cfg,
Logger: logger,
Config: cfg,
Logger: logger,
Version: gitVersion(),
}

if info, ok := debug.ReadBuildInfo(); ok {
rs.Version = info.Main.Version
logger.Debug("main: using scwtui version",
slog.String("version", rs.Version),
slog.String("go_version", info.GoVersion),
)
}
logger.Info("starting scwtui", slog.String("version", rs.Version))

err = ctx.Run(rs)
ctx.FatalIfErrorf(err)
Expand All @@ -66,3 +61,18 @@ func initLogger(config config.Config) (*slog.Logger, error) {
})
return slog.New(loggerHandler), nil
}

func gitVersion() string {
info, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}

for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}

return "development"
}

0 comments on commit 1a0195e

Please sign in to comment.