Skip to content

Commit

Permalink
Merge pull request #1 from fortio/fix_non_main_version
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly authored Sep 14, 2023
2 parents d8b0e12 + 45989b0 commit f1f5b85
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func normalizeVersion(version string) string {
return short
}

func getVersion(binfo *debug.BuildInfo, path string) (short, sum, mainPath, base string) {
func getVersion(binfo *debug.BuildInfo, path string) (short, sum, mainPath, base string, isMain bool) {
mainPath = binfo.Main.Path
base = normalizeVersion(binfo.Main.Version)
if path == "" || path == mainPath {
sum = binfo.Main.Sum
short = base
isMain = true
return
}
// try to find the right module in deps
Expand All @@ -71,9 +72,9 @@ func FromBuildInfoPath(path string) (short, long, full string) {
log.Print("Error calling debug.ReadBuildInfo() for fortio version module")
return
}
short, sum, mainPath, base := getVersion(binfo, path)
short, sum, mainPath, base, isMain := getVersion(binfo, path)
long = short + " " + sum + " " + binfo.GoVersion + " " + runtime.GOARCH + " " + runtime.GOOS
if short != base {
if !isMain {
long = long + " (in " + mainPath + " " + base + ")"
}
full = fmt.Sprintf("%s\n%v", long, binfo.String())
Expand Down

0 comments on commit f1f5b85

Please sign in to comment.