oauth2-authorize-server/internal/vcs/vcs.go
2025-01-02 11:54:15 +08:00

32 lines
517 B
Go

package vcs
import (
"fmt"
"runtime/debug"
)
func Version() string {
var revision string
var modified bool
var time string
bi, ok := debug.ReadBuildInfo()
if ok {
for _, s := range bi.Settings {
switch s.Key {
case "vcs.time":
time = s.Value
case "vcs.revision":
revision = s.Value
case "vcs.modified":
if s.Value == "true" {
modified = true
}
}
}
}
if modified {
return fmt.Sprintf("%s-%s-dirty", time, revision)
}
return fmt.Sprintf("%s-%s", time, revision)
}