From fa6f9cd56300cb2388dfc734274d93e42951f981 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Fri, 9 Jun 2023 15:40:42 +0200 Subject: [PATCH] Expose module version (#53) --- version/info.go | 15 +++++++++++++++ version/mod.go | 2 ++ 2 files changed, 17 insertions(+) diff --git a/version/info.go b/version/info.go index 5045920..ac49ffe 100644 --- a/version/info.go +++ b/version/info.go @@ -12,6 +12,7 @@ var ( buildUser string buildDate string dependencies map[string]string + main string ) // Information holds app version info. @@ -38,6 +39,20 @@ func Info() Information { } } +// Module returns module version info. +func Module(path string) Information { + info := Info() + + if main == path { + return info + } + + ver := dependencies[path] + info.Version = ver + + return info +} + // String return version information as string. func (i Information) String() string { res := "" diff --git a/version/mod.go b/version/mod.go index efbc03b..ee71265 100644 --- a/version/mod.go +++ b/version/mod.go @@ -18,6 +18,8 @@ func init() { buildDate = "(unknown)" } + main = info.Main.Path + dependencies = make(map[string]string, len(info.Deps)) for _, dep := range info.Deps { dependencies[dep.Path] = dep.Version