Giter Site home page Giter Site logo

go-version's Introduction

go-version

Introduction

In all of my programs, I like to have a pretty little line at the top stating some key facts about the programs compile.

Example:

cloudkey version v1.0.0-rc2 git revision fe3428954dfd97d850ca687badcace28102e351d go version go1.12

I was tiring of writing this over, and over, and over again, so I just made a package.

Usage

At the top of main.go

import (
	_ "github.com/jnovack/go-version"
)

Then, when you build, add these variables to the command line:

APPLICATION=$(shell basename `pwd`)
BUILD_RFC3339=$(shell date -u +"%Y-%m-%dT%H:%M:%S+00:00")
COMMIT=$(shell git rev-parse HEAD)
VERSION=$(shell git describe --tags)
GO_LDFLAGS="-w -s \
    -X github.com/jnovack/go-version.Application=${APPLICATION} \
    -X github.com/jnovack/go-version.BuildDate=${BUILD_RFC3339} \
	-X github.com/jnovack/go-version.Revision=${COMMIT} \
	-X github.com/jnovack/go-version.Version=${VERSION}
	"

go build -ldflags "GO_LDFLAGS" main.go

or use a Makefile and do not be a scrub.

Variables

All the variables are exported, so you can reference them within your code.

var (
	// Application supplied by the linker
	Application = "go-application"
	// BuildRFC3339 supplied by the linker
	BuildRFC3339 = "1970-01-01T00:00:00+00:00"
	// Version supplied by the linker
	Version = "v0.0.0"
	// Commit supplied by the linker
	Commit = "00000000"
	// GoVersion supplied by the runtime
	GoVersion = runtime.Version()
)

go-version's People

Contributors

jnovack avatar

Watchers

 avatar  avatar

Forkers

kharloss

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.