v

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: MIT Imports: 1 Imported by: 49

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"

Documentation

Overview

Package v simplifies printing version information of an application.

Add the following to your main.go

package main

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

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

And in your 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

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version of the application
	Version = "version not set, please build your app with appropriate ldflags, see https://github.com/metal-stack/v for reference"
	// Revision of the application
	Revision = ""
	// GitSHA1 of the application
	GitSHA1 = ""
	// BuildDate of the application
	BuildDate = ""
)
View Source
var V = &version{}

V the version

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd module

Jump to

Keyboard shortcuts

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