Skip to content

Commit fa6f9cd

Browse files
authored
Expose module version (#53)
1 parent 90845c2 commit fa6f9cd

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

version/info.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var (
1212
buildUser string
1313
buildDate string
1414
dependencies map[string]string
15+
main string
1516
)
1617

1718
// Information holds app version info.
@@ -38,6 +39,20 @@ func Info() Information {
3839
}
3940
}
4041

42+
// Module returns module version info.
43+
func Module(path string) Information {
44+
info := Info()
45+
46+
if main == path {
47+
return info
48+
}
49+
50+
ver := dependencies[path]
51+
info.Version = ver
52+
53+
return info
54+
}
55+
4156
// String return version information as string.
4257
func (i Information) String() string {
4358
res := ""

version/mod.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func init() {
1818
buildDate = "(unknown)"
1919
}
2020

21+
main = info.Main.Path
22+
2123
dependencies = make(map[string]string, len(info.Deps))
2224
for _, dep := range info.Deps {
2325
dependencies[dep.Path] = dep.Version

0 commit comments

Comments
 (0)