version: make all exported funcs compile-time constant or lazy

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2023-02-10 18:07:37 -08:00
committed by Dave Anderson
parent 8b2ae47c31
commit 70a2929a12
9 changed files with 240 additions and 183 deletions

View File

@ -7,25 +7,27 @@ import (
"fmt"
"runtime"
"strings"
"tailscale.com/types/lazy"
)
func String() string {
var stringLazy = lazy.SyncFunc(func() string {
var ret strings.Builder
ret.WriteString(short)
ret.WriteString(Short())
ret.WriteByte('\n')
if IsUnstableBuild() {
fmt.Fprintf(&ret, " track: unstable (dev); frequent updates and bugs are likely\n")
}
if gitCommit != "" {
var dirty string
if gitDirty {
dirty = "-dirty"
}
fmt.Fprintf(&ret, " tailscale commit: %s%s\n", gitCommit, dirty)
if gitCommit() != "" {
fmt.Fprintf(&ret, " tailscale commit: %s%s\n", gitCommit(), dirtyString())
}
if extraGitCommit != "" {
fmt.Fprintf(&ret, " other commit: %s\n", extraGitCommit)
if extraGitCommitStamp != "" {
fmt.Fprintf(&ret, " other commit: %s\n", extraGitCommitStamp)
}
fmt.Fprintf(&ret, " go version: %s\n", runtime.Version())
return strings.TrimSpace(ret.String())
})
func String() string {
return stringLazy()
}