Help us shape the future of Go! Take the 2026 Go Developer Survey

version

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package version provides semantic version parsing, comparison, and development-build detection via the [Version] interface. Build-time version strings injected via ldflags are parsed into structured values for display and update-check comparison.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(v, w string) int

CompareVersions returns an integer comparing two versions according to semantic version precedence.

func FormatVersionString

func FormatVersionString(version string, prefixWanted bool) string

FormatVersionString adds or removes a "v" prefix from version string.

func IsReleaseTag added in v0.49.0

func IsReleaseTag(v string) bool

IsReleaseTag reports whether v names a release as tags are written: v-prefixed, three-part, optionally a prerelease. Canonical refuses the shorthands (v1, v1.2) and build metadata that IsValid alone accepts.

Types

type Info

type Info struct {
	Version string `json:"version" yaml:"version"`
	Commit  string `json:"commit" yaml:"commit"`
	Date    string `json:"date" yaml:"date"`
}

Info holds a build's version information. Its zero value means the binary was not stamped; see IsZero.

func NewInfo

func NewInfo(v, c, d string) Info

NewInfo creates a new Info instance.

func (Info) Compare

func (i Info) Compare(other string) int

func (Info) GetCommit

func (i Info) GetCommit() string

func (Info) GetDate

func (i Info) GetDate() string

func (Info) GetVersion

func (i Info) GetVersion() string

func (Info) IsDevelopment

func (i Info) IsDevelopment() bool

IsDevelopment reports whether this is not a release build: an invalid version, a Go pseudo-version (what go build and go install ...@main stamp from a commit), a prerelease carrying a dev or dirty segment, or any build metadata (a VCS-stamped module build reports the tag plus "+dirty").

func (Info) IsZero added in v0.43.0

func (i Info) IsZero() bool

IsZero reports whether no version was stamped into the binary.

func (Info) String

func (i Info) String() string

Jump to

Keyboard shortcuts

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