version

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 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 resolves the version string a binary reports.

There are two ways a build gets one, and a binary has to handle both:

  • A release build passes it explicitly, with -ldflags="-X main.version=1.46.0". This is what the Dockerfiles do, and it is the only way to get the exact tag being released.
  • `go install module/cmd/x@v1.46.0` passes no ldflags at all, but the Go toolchain embeds the module version it resolved, which Resolve reads back. Without this a go-installed binary reports "dev" and gives its user no way to tell what they are running.

A plain `go build` from a working tree gets no ldflags either, but the toolchain stamps a version derived from VCS — "v1.46.0+dirty" for a tree with uncommitted changes — which is more use than a placeholder, so it is reported as-is. Only when there is no version to derive, as with -buildvcs=false or outside a repository, does the toolchain report "(devel)"; that is not a version and the placeholder stands instead.

Verified against all four paths: ldflags wins; `go install ...@v1.46.0` reports v1.46.0; `go build` reports v1.46.0+dirty; `go build -buildvcs=false` reports the placeholder.

Index

Constants

View Source
const Placeholder = "dev"

Placeholder is what a main package's version variable holds until a build overrides it. Resolve treats it as "nothing was passed".

Variables

This section is empty.

Functions

func Resolve

func Resolve(ldflagsVersion string) string

Resolve returns the version to report. ldflagsVersion is the main package's version variable: it wins when a build set it, and otherwise the version the Go toolchain embedded is used.

Types

This section is empty.

Jump to

Keyboard shortcuts

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