mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
version: find from build info if unset
Some checks failed
Some checks failed
This commit is contained in:
parent
d146b6caf8
commit
f2b77f0433
3 changed files with 15 additions and 3 deletions
12
version.go
12
version.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -18,6 +19,17 @@ var DefaultUserAgent = "mautrix-go/" + Version + " go/" + strings.TrimPrefix(run
|
|||
var goModVersionRegex = regexp.MustCompile(`v.+\d{14}-([0-9a-f]{12})`)
|
||||
|
||||
func init() {
|
||||
if GoModVersion == "" {
|
||||
info, _ := debug.ReadBuildInfo()
|
||||
if info != nil {
|
||||
for _, mod := range info.Deps {
|
||||
if mod.Path == "maunium.net/go/mautrix" {
|
||||
GoModVersion = mod.Version
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if GoModVersion != "" {
|
||||
match := goModVersionRegex.FindStringSubmatch(GoModVersion)
|
||||
if match != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue