-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App version is taken from version.json compiled in
This ensures that the version is always set to the correct value. making version.json the source of truth. Fixes #146 Fixes #113
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"runtime/debug" | ||
) | ||
|
||
var version string | ||
|
||
//go:embed version.json | ||
var versionJSON []byte | ||
|
||
func init() { | ||
// Read version from embedded JSON file. | ||
var verMap map[string]string | ||
json.Unmarshal(versionJSON, &verMap) | ||
version = verMap["version"] | ||
|
||
// If running from a module, try to get the build info. | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return | ||
} | ||
|
||
// Append the revision to the version. | ||
for i := range bi.Settings { | ||
if bi.Settings[i].Key == "vcs.revision" { | ||
version += "-" + bi.Settings[i].Value | ||
break | ||
} | ||
} | ||
} |