mirror of
https://github.com/criyle/go-judge.git
synced 2025-09-26 22:39:12 +08:00
34 lines
576 B
Go
34 lines
576 B
Go
package version
|
|
|
|
import (
|
|
"embed"
|
|
"io"
|
|
"runtime/debug"
|
|
"strings"
|
|
)
|
|
|
|
//go:embed version.*
|
|
var versions embed.FS
|
|
|
|
// Version defines the version of go-judge
|
|
var Version string = "unable to get version"
|
|
|
|
func init() {
|
|
f, err := versions.Open("version.txt")
|
|
if err != nil {
|
|
// go generate was not run, assuming installed by go install
|
|
// get version information from debug
|
|
inf, ok := debug.ReadBuildInfo()
|
|
if !ok {
|
|
return
|
|
}
|
|
Version = inf.Main.Version
|
|
return
|
|
}
|
|
s, err := io.ReadAll(f)
|
|
if err != nil {
|
|
return
|
|
}
|
|
Version = strings.TrimSpace(string(s))
|
|
}
|