version

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 4 Imported by: 0

README

version

Build-time version information with Git metadata, injected via -ldflags.

Install

go get github.com/kbukum/gokit

Quick Start

package main

import (
    "fmt"
    "github.com/kbukum/gokit/version"
)

func main() {
    info := version.GetVersionInfo()
    fmt.Println(info.Version)   // e.g. "1.2.3"
    fmt.Println(info.GitCommit) // e.g. "abc1234"
    fmt.Println(info.GitBranch) // e.g. "main"

    fmt.Println(version.GetShortVersion()) // "1.2.3-abc1234"
    fmt.Println(version.GetFullVersion())  // "1.2.3-abc1234 (main, 2024-01-15)"
}

Build with ldflags:

go build -ldflags "-X github.com/kbukum/gokit/version.Version=1.2.3 \
  -X github.com/kbukum/gokit/version.GitCommit=$(git rev-parse --short HEAD) \
  -X github.com/kbukum/gokit/version.GitBranch=$(git rev-parse --abbrev-ref HEAD) \
  -X github.com/kbukum/gokit/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)"

Key Types & Functions

Name Description
Info Struct with Version, GitCommit, GitBranch, BuildTime, GoVersion
GetVersionInfo() Returns full *Info struct
GetShortVersion() Returns version-commit string
GetFullVersion() Returns detailed version string
Version / GitCommit / GitBranch / BuildTime Linker-injected variables

⬅ Back to main README

Documentation

Overview

Package version provides build version information embedding for gokit applications.

Version, git commit, branch, and build time are set at compile time via -ldflags:

go build -ldflags "-X github.com/kbukum/gokit/version.Version=1.0.0"

Index

Constants

This section is empty.

Variables

View Source
var (
	// These variables are set at build time using -ldflags
	Version   = "dev" // Version from git tag or manual override
	GitCommit = ""    // Git commit hash
	GitBranch = ""    // Git branch name
	BuildTime = ""    // Build timestamp
	GoVersion = ""    // Go version used for build
)

Functions

func GetFullVersion

func GetFullVersion() string

GetFullVersion returns a detailed version string

func GetShortVersion

func GetShortVersion() string

GetShortVersion returns a short version string

Types

type Info

type Info struct {
	Version   string    `json:"version"`
	GitCommit string    `json:"git_commit"`
	GitBranch string    `json:"git_branch"`
	BuildTime string    `json:"build_time"`
	GoVersion string    `json:"go_version"`
	BuildDate time.Time `json:"build_date"`
	IsRelease bool      `json:"is_release"`
	IsDirty   bool      `json:"is_dirty"`
}

Info represents version information

func GetVersionInfo

func GetVersionInfo() *Info

GetVersionInfo returns comprehensive version information

Jump to

Keyboard shortcuts

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