version

package
v0.115.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package version exposes build identity variables that are injected at link time via -ldflags. Using ldflags guarantees the binary always carries its true version regardless of whether service.yaml is present.

Canonical build command:

go build \
  -ldflags "-X github.com/baditaflorin/go-common/version.Tag=$(git describe --tags --always) \
             -X github.com/baditaflorin/go-common/version.GitCommit=$(git rev-parse --short HEAD) \
             -X github.com/baditaflorin/go-common/version.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
  ./...

In development (no ldflags), all variables default to their zero-value sentinels ("dev", "HEAD", "unknown") so logs are always unambiguous.

Usage:

import "github.com/baditaflorin/go-common/version"

fmt.Println(version.Tag)         // "v1.4.2"
fmt.Println(version.GitCommit)   // "a3f9b1c"
fmt.Println(version.BuildDate)   // "2026-05-19T14:23:00Z"
fmt.Println(version.String())    // "v1.4.2 (a3f9b1c, built 2026-05-19T14:23:00Z)"

Index

Constants

This section is empty.

Variables

View Source
var BuildDate = "unknown"

BuildDate is the UTC build timestamp in RFC3339 format. Injected via: -ldflags "-X github.com/baditaflorin/go-common/version.BuildDate=2026-05-19T14:23:00Z"

View Source
var GitCommit = "HEAD"

GitCommit is the short git commit SHA, e.g. "a3f9b1c". Injected via: -ldflags "-X github.com/baditaflorin/go-common/version.GitCommit=a3f9b1c"

View Source
var GoVersion = goVersion()

GoVersion is the Go toolchain version used to build the binary. This is populated automatically at runtime via runtime.Version() and does not need ldflags injection.

View Source
var Tag = "dev"

Tag is the git tag or semver string, e.g. "v1.4.2". Injected via: -ldflags "-X github.com/baditaflorin/go-common/version.Tag=v1.4.2"

Functions

func Info

func Info() map[string]string

Info returns a structured map suitable for JSON serialisation. Use in /version endpoints alongside config.Load() fields.

func String

func String() string

String returns a single-line human-readable version string suitable for /version responses, log startup lines, and User-Agent headers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL