Skip to content

Commit

Permalink
Expose module version (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Jun 9, 2023
1 parent 90845c2 commit fa6f9cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions version/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
buildUser string
buildDate string
dependencies map[string]string
main string
)

// Information holds app version info.
Expand All @@ -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 := ""
Expand Down
2 changes: 2 additions & 0 deletions version/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa6f9cd

Please sign in to comment.