Categorygithub.com/metal-stack/v
modulepackage
1.0.3
Repository: https://github.com/metal-stack/v.git
Documentation: pkg.go.dev

# README

v

Actions Go Report Card GoDoc codecov License

v simplifies printing version information of an application.

Quickstart

Add the following to your main.go

package main

import (
    "log"
    "github.com/metal-stack/v"
)

func main() {
    log.Info("application", "version", v.V)
}

Modify you build target in the Makefile:

.ONESHELL:
SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
BUILDDATE := $(shell date -Iseconds)
VERSION := $(or ${VERSION},devel)

BINARY := application

${BINARY}: clean test
    GGO_ENABLED=0 \
    GO111MODULE=on \
    go build \
    -tags netgo \
    -ldflags "-X 'github.com/metal-stack/v.Version=$(VERSION)' \
              -X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
              -X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
              -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
    -o application

Compile and run:

make application

Expected output:

[...]
INFO[10-29|14:22:34] application   version="devel (0b016992), heads/master-0-g0b01699, 2019-05-29T14:22:26+01:00, go1.16"

# Variables

BuildDate of the application.
GitSHA1 of the application.
Revision of the application.
V the version.
Version of the application.