44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package version
|
|
|
|
import (
|
|
"runtime"
|
|
"runtime/debug"
|
|
)
|
|
|
|
// Identity describes the executable itself, without consulting a checkout that
|
|
// may have changed since it was built. Missing VCS stamps remain explicit.
|
|
type Identity struct {
|
|
GoVersion string `json:"go_version"`
|
|
Revision string `json:"vcs_revision"`
|
|
Time string `json:"vcs_time"`
|
|
Modified string `json:"vcs_modified"`
|
|
}
|
|
|
|
func RuntimeIdentity() Identity {
|
|
info, _ := debug.ReadBuildInfo()
|
|
return build_identity(info)
|
|
}
|
|
|
|
func build_identity(info *debug.BuildInfo) Identity {
|
|
identity := Identity{GoVersion: runtime.Version(), Revision: "unknown", Time: "unknown", Modified: "unknown"}
|
|
if info == nil {
|
|
return identity
|
|
}
|
|
identity.GoVersion = info.GoVersion
|
|
for _, setting := range info.Settings {
|
|
switch setting.Key {
|
|
case "vcs.revision":
|
|
identity.Revision = setting.Value
|
|
case "vcs.time":
|
|
identity.Time = setting.Value
|
|
case "vcs.modified":
|
|
identity.Modified = setting.Value
|
|
}
|
|
}
|
|
return identity
|
|
}
|