63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
// Package version carries build identification for the binary.
|
|
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"runtime/debug"
|
|
)
|
|
|
|
// These are overridable at build time with -ldflags.
|
|
var (
|
|
Version = "0.1.0"
|
|
Commit = ""
|
|
BuildDate = ""
|
|
)
|
|
|
|
// Name is the product name shown in the UI and on the CLI.
|
|
const Name = "VibeDNS"
|
|
|
|
func init() {
|
|
if Commit != "" {
|
|
return
|
|
}
|
|
info, ok := debug.ReadBuildInfo()
|
|
if !ok {
|
|
return
|
|
}
|
|
for _, s := range info.Settings {
|
|
switch s.Key {
|
|
case "vcs.revision":
|
|
if len(s.Value) > 12 {
|
|
Commit = s.Value[:12]
|
|
} else {
|
|
Commit = s.Value
|
|
}
|
|
case "vcs.time":
|
|
if BuildDate == "" {
|
|
BuildDate = s.Value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Short returns just the semantic version.
|
|
func Short() string { return Version }
|
|
|
|
// Long returns a multi-line description suitable for `vibedns version`.
|
|
func Long() string {
|
|
s := fmt.Sprintf("%s %s\n", Name, Version)
|
|
if Commit != "" {
|
|
s += fmt.Sprintf("commit: %s\n", Commit)
|
|
}
|
|
if BuildDate != "" {
|
|
s += fmt.Sprintf("built: %s\n", BuildDate)
|
|
}
|
|
s += fmt.Sprintf("go: %s\n", runtime.Version())
|
|
s += fmt.Sprintf("platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
|
return s
|
|
}
|
|
|
|
// UserAgent identifies the server in outbound HTTP requests.
|
|
func UserAgent() string { return Name + "/" + Version }
|