version

package
v0.11.8 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: GPL-3.0 Imports: 3 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 reports the version and build metadata of the cem binary and of programs that embed cem packages.

It is intended for external consumption. The package is part of the supported public Go API, so it follows the compatibility policy described in CONTRIBUTING.md.

A build can inject metadata with -ldflags -X, for example:

go build -ldflags "\
  -X bennypowers.dev/cem/version.Version=v1.2.3 \
  -X bennypowers.dev/cem/version.GitCommit=abcdef1 \
  -X bennypowers.dev/cem/version.GitTag=v1.2.3" .

When the metadata is absent, Get reads the Go build information. If cem is the main module, it uses that module's version. If cem is embedded as a dependency, it reports the cem dependency version, honoring any Replace directive, rather than the host program's version. If no module version is available, Get assembles a version from GitTag, GitCommit, and GitDirty when they are set, and finally returns "dev".

Usage:

fmt.Println("cem", version.Get())
for key, value := range version.Info() {
	fmt.Printf("%s: %s\n", key, value)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is the release version, for example "v1.2.3". It is normally
	// set at build time with -ldflags -X and defaults to "dev".
	Version = "dev"

	// GitCommit is the full or abbreviated git commit hash. It is normally
	// set at build time with -ldflags -X and defaults to "unknown".
	GitCommit = "unknown"

	// GitTag is the git tag at build time. It is normally set at build time
	// with -ldflags -X and defaults to "unknown".
	GitTag = "unknown"

	// BuildTime is the RFC 3339 build timestamp. It is normally set at build
	// time with -ldflags -X and defaults to "unknown".
	BuildTime = "unknown"

	// GitDirty is "dirty" when the working tree contained uncommitted changes
	// at build time. It is normally set at build time with -ldflags -X and
	// defaults to the empty string.
	GitDirty = ""
)

Functions

func Full

func Full() string

Full returns the version string with the commit hash appended when it is known.

func Get

func Get() string

Get returns the version string for the application.

It prefers the value injected at build time, then a usable version from Go build information, then a string assembled from git metadata, and finally "dev". For build information, it uses the main module version when cem is the main module; otherwise it scans dependencies for the cem module, so embedders report cem's version rather than the host program's version.

func Info

func Info() map[string]string

Info returns the version and build metadata as a map suitable for JSON encoding. Keys are "version", "gitCommit", "gitTag", "buildTime", and "gitDirty".

Types

This section is empty.

Jump to

Keyboard shortcuts

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