mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Allow compiling commit hash into user agent
This commit is contained in:
parent
72a1c344d1
commit
e464b24910
1 changed files with 27 additions and 1 deletions
28
version.go
28
version.go
|
|
@ -1,5 +1,31 @@
|
|||
package mautrix
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const Version = "v0.15.1"
|
||||
|
||||
var DefaultUserAgent = "mautrix-go/" + Version
|
||||
var GoModVersion = ""
|
||||
var Commit = ""
|
||||
var VersionWithCommit = Version
|
||||
|
||||
var DefaultUserAgent = "mautrix-go/" + Version + " go/" + strings.TrimPrefix(runtime.Version(), "go")
|
||||
|
||||
var goModVersionRegex = regexp.MustCompile(`v.+\d{14}-([0-9a-f]{12})`)
|
||||
|
||||
func init() {
|
||||
if GoModVersion != "" {
|
||||
match := goModVersionRegex.FindStringSubmatch(GoModVersion)
|
||||
if match != nil {
|
||||
Commit = match[1]
|
||||
}
|
||||
}
|
||||
if Commit != "" {
|
||||
VersionWithCommit = fmt.Sprintf("%s+dev.%s", Version, Commit[:8])
|
||||
DefaultUserAgent = strings.Replace(DefaultUserAgent, "mautrix-go/"+Version, "mautrix-go/"+VersionWithCommit, 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue