mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-12-24 12:57:56 +08:00
Set app version from git info
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -91,6 +92,14 @@ func Init() {
|
||||
|
||||
func readRevisionTime() (revision, vcsTime string) {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
// Rewrite version from -buildvcs info if it is valid.
|
||||
// Format for tagged version: v1.9.13
|
||||
// Format for custom commit: v1.9.14-0.20251215184105-753d6617ab58
|
||||
// Format for modified code: v1.9.14-0.20251215184105-753d6617ab58+dirty
|
||||
if s, ok := strings.CutPrefix(info.Main.Version, "v"); ok {
|
||||
Version = s
|
||||
}
|
||||
|
||||
for _, setting := range info.Settings {
|
||||
switch setting.Key {
|
||||
case "vcs.revision":
|
||||
@@ -103,7 +112,7 @@ func readRevisionTime() (revision, vcsTime string) {
|
||||
vcsTime = setting.Value
|
||||
case "vcs.modified":
|
||||
if setting.Value == "true" {
|
||||
revision = "mod." + revision
|
||||
revision += "+dirty"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user