buildinfo/buildInfo.go

53 lines
920 B
Go

package buildinfo
type buildInfo struct {
Name string
Version string
Commit string
BuildTime string
OS string
Arch string
ShowDeps bool
Deps []Dep
}
type Options struct {
BuildTime bool
Commit bool
OsArch bool
Deps bool
}
type Dep struct {
Name string
Version string
Sum string
}
func newBuildInfo(options Options) *buildInfo {
buildTime := iff(options.BuildTime, BuildTime, "")
commit := iff(options.Commit, Commit, "")
os := iff(options.OsArch, OS, "")
arch := iff(options.OsArch, Arch, "")
showDeps := iff(options.Deps, true, false)
return &buildInfo{
Name: Name,
Version: Version,
Deps: dependencies,
Commit: commit,
BuildTime: buildTime,
OS: os,
Arch: arch,
ShowDeps: showDeps,
}
}
func iff[T any](condition bool, trueValue, falseValue T) T {
if condition {
return trueValue
}
return falseValue
}