Documentation
¶
Overview ¶
Package metadata provides application version and build information. It uses Go build information (debug.ReadBuildInfo) to populate version at runtime, and can be extended with build-time flags for commit SHA and build timestamp.
Usage ¶
import "github.com/PapagoLabs/outtake/internal/metadata"
fmt.Printf("%s %s\n", metadata.Name, metadata.String())
info := metadata.GetInfo() // structured data for JSON/output
Build-time Injection ¶
To set Version, CommitSHA, and BuildTime at build time, use ldflags:
go build -ldflags "-X 'github.com/PapagoLabs/outtake/internal/metadata.Version=v1.0.0' \ -X 'github.com/PapagoLabs/outtake/internal/metadata.CommitSHA=abc123' \ -X 'github.com/PapagoLabs/outtake/internal/metadata.BuildTime=2025-01-15T12:00:00Z'"
Index ¶
Constants ¶
const ( // Name is the application name. Name = "outtake" // DefaultVersion is used when no version information is available. DefaultVersion = "dev" )
Variables ¶
var ( // Version is the full semantic version string. Version = DefaultVersion // CommitSHA is the git commit hash at build time. CommitSHA = "" // BuildTime is the timestamp of the build. BuildTime = "" )
Functions ¶
func ConvertToLocal ¶
ConvertToLocal converts an RFC3339 UTC timestamp to a local time string.
Parameters:
- utcStr: The UTC timestamp in RFC3339 format.
Returns:
- string: The formatted local time string, or empty string if input is empty. Returns the original string if parsing fails.
func GetGoVersion ¶
func GetGoVersion() string
GetGoVersion returns the Go toolchain version, or "unknown" if unavailable.
Returns:
- string: The Go version string from build info, or "unknown".
func PrintDefault ¶
PrintDefault writes the single-line version string to writer.
Parameters:
- writer: The output writer to write the version string to.
Returns:
- error: Non-nil if writing to the writer fails.
func PrintJSON ¶
PrintJSON writes version info as indented JSON to writer.
Parameters:
- writer: The output writer to encode JSON to.
Returns:
- error: Non-nil if JSON encoding fails.
func PrintVerbose ¶
PrintVerbose writes multi-line detailed version info to writer.
Parameters:
- writer: The output writer to write the version details to.
Returns:
- error: Non-nil if writing to the writer fails.
Types ¶
type VersionInfo ¶
type VersionInfo struct {
// Name is the application name.
Name string `json:"name"`
// Version is the semantic version string.
Version string `json:"version"`
// CommitSHA is the git commit hash at build time (omitted if empty).
CommitSHA string `json:"commitSha,omitempty"`
// BuildTime is the timestamp of the build (omitted if empty).
BuildTime string `json:"buildTime,omitempty"`
// GoVersion is the Go toolchain version used for the build.
GoVersion string `json:"goVersion,omitempty"`
// OS is the operating system the build was compiled for.
OS string `json:"os"`
// Arch is the CPU architecture the build was compiled for.
Arch string `json:"arch"`
}
VersionInfo holds complete version data for display/export.
func GetInfo ¶
func GetInfo() VersionInfo
GetInfo returns populated VersionInfo with raw version (no commit suffix).
Returns:
- VersionInfo: Structured version data for display or serialization.