https://github.com/jnovack/go-version
Package to easily version your application
https://github.com/jnovack/go-version
bad-idea deprecated wrong-way
Last synced: 5 months ago
JSON representation
Package to easily version your application
- Host: GitHub
- URL: https://github.com/jnovack/go-version
- Owner: jnovack
- License: mit
- Created: 2018-10-14T11:55:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-10T11:19:45.000Z (almost 4 years ago)
- Last Synced: 2024-06-20T17:53:56.584Z (about 2 years ago)
- Topics: bad-idea, deprecated, wrong-way
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# 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()
)
```