ldflags/README.md

26 lines
1.2 KiB
Markdown
Raw Normal View History

2020-10-04 21:04:31 +02:00
# ldflags package
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fversion-go%2Fldflags.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fversion-go%2Fldflags?ref=badge_shield)
2020-10-03 17:15:48 +02:00
Package to store on-build extra information: version(tag), build hash, build time
2020-10-04 21:04:31 +02:00
## Usage
Add this package as dependency to YOUR package:
```bash
go get github.com/version-go/ldflags
```
Then on build of YOUR package just add extra:
```bash
2020-10-05 20:23:48 +02:00
go build -ldflags "-X 'github.com/version-go/ldflags.buildVersion=0.1.0' -X 'github.com/version-go/ldflags.buildHash=9e7637c' -X 'github.com/version-go/ldflags.buildTime=Sun Oct 4 20:57:29 CEST 2020'" .
2020-10-04 21:04:31 +02:00
```
Or do it automatically based on existing git/data:
```bash
2020-10-05 20:23:48 +02:00
go build -ldflags "-X 'github.com/version-go/ldflags.buildVersion=$(git describe --abbrev=0 --tags)' -X 'github.com/version-go/ldflags.buildHash=$(git rev-parse --short HEAD)' -X 'github.com/version-go/ldflags.buildTime=$(date)'" .
2020-10-04 21:04:31 +02:00
```
will store current latest tag, commit hash and build time.
## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fversion-go%2Fldflags.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fversion-go%2Fldflags?ref=badge_large)