Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // BuildTime is the timestamp when the binary was built, injected by -ldflags BuildTime string = "..." // Who identifies the builder of this binary, injected by -ldflags Who string = "..." // State indicates whether the build was from a clean working directory, injected by -ldflags State string = "..." // VersionTag is the semantic version of the application, injected by -ldflags VersionTag = "0.1.0" )
These attributes should only be changed by the build script, do not change it manually.
Functions ¶
func PrintVersion ¶
PrintVersion prints the build information to the specified writer This is useful for CLI applications where you want to output version info to stdout, stderr, or a log file
Types ¶
type BuildInfo ¶
type BuildInfo struct {
// BuildSha is the Git commit SHA, injected by -ldflags during build
BuildSha string
// BuildTime is the timestamp when the binary was built, injected by -ldflags
BuildTime string
// Who identifies the builder of this binary, injected by -ldflags
Who string
// State indicates whether the build was from a clean working directory, injected by -ldflags
State string
// Version is the semantic version of the application, injected by -ldflags
Version string
// GoVersion is the Go version used to build the binary (e.g., "go1.18.3")
GoVersion string
// Path is the main module path
Path string
// Main contains information about the main module
Main Module
// Dependencies contains information about all dependencies
Dependencies []Module
// BuildMode indicates how the binary was built (e.g., "exe")
BuildMode string
// Compiler indicates which compiler was used (e.g., "gc")
Compiler string
// CGOEnabled indicates whether CGO was enabled during build
CGOEnabled string
// GOOS is the target operating system (e.g., "darwin", "linux")
GOOS string
// GOARCH is the target architecture (e.g., "amd64", "arm64")
GOARCH string
// GOARMVersion specifies the ARM version if GOARCH is "arm" or "arm64"
GOARMVersion string
// VCS identifies the version control system (e.g., "git")
VCS string
// VCSRevision is the full commit hash from version control
VCSRevision string
// VCSTime is the commit timestamp from version control
VCSTime string
// VCSModified indicates whether the working directory had uncommitted changes
VCSModified string
// Raw build settings for any custom or additional settings
RawSettings []BuildSetting
}
BuildInfo contains comprehensive version and build information from both custom ldflags injection and Go's runtime/debug package.
func GetBuildInfo ¶
func GetBuildInfo() BuildInfo
GetBuildInfo returns comprehensive version information by combining manually injected build variables with Go's runtime build information
func (BuildInfo) PrettyPrint ¶
PrettyPrint formats build information in a human-readable way for CLI applications It returns a string containing formatted build information with proper indentation and grouping
type BuildSetting ¶
type BuildSetting struct {
// Key is the name of the build setting
Key string
// Value is the value of the build setting
Value string
}
BuildSetting represents an individual build setting key-value pair
type Module ¶
type Module struct {
// Path is the import path of the module
Path string
// Version is the module version
Version string
// Sum is the checksum of the module
Sum string
// Replace points to a replacement if this module is replaced
Replace *Module
}
Module represents a Go module with its version information