version

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 4 Imported by: 0

README

go-version

Go package for version and build info.

It helps you expose version information (version, git commit, build date, Go version and platform) across different Go projects.


Setup

Add the package to your project:

go get github.com/ghdrope/go-version

Usage

Basic Example
import (
	"fmt"
	"github.com/ghdrope/go-version"
)

func main() {
	fmt.Println(version.String())
}
Short Version Only
fmt.Println(version.Short())
Structured Print
info := version.Get()

fmt.Println(info.Version)
fmt.Println(info.GitCommit)
fmt.Println(info.BuildDate)
fmt.Println(info.GoVersion)
fmt.Println(info.Platform)

CLI Usage Example

You can easily expose it via a CLI command (example using cobra):

Run: func(cmd *cobra.Command, _ []string) {
	fmt.Println(version.String())
}

Optional short flag:

if short {
	fmt.Println(version.Short())
	return
}

See a full usage example in the project wis2-ingest


Build Info Injection

These values are typically injected at build using ldflags:

go build -ldflags "
	-X github.com/ghdrope/go-version.Version=v1.0.0
	-X github.com/ghdrope/go-version.GitCommit=abc123
	-X github.com/ghdrope/go-version.BuildDate=2026-01-01"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "development"
	GitCommit = "none"
	BuildDate = "unknown"
)

These variables are set at build time using -ldflags. Default values are used when running locally (e.g. `go run`).

Functions

func Short

func Short() string

Short returns only version (helper).

func String

func String() string

String returns full version info directly (helper).

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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