I am so sorry, this post article is not completed yet. I forgot to finalize it even though I already have had sample code.
Hello every body, welcome to my blog!
This time I will share with you, how to generate go app version using go:generate
.
Ok, without further ado, let’s get started.
In this tutorial, we’ll use a demo project as shown at below image:
I will share the source code at the end of this article.
There are 4 parts that construct our demo project:
cmd/cli.go
, is the main app that will show its version and buildtime when it is executed using this command./bin/cli -version
bin
, is a directory where the build will be storedinternal/vcs/vcs.go
, is shareable code which its main purpose is to generate version based git tag dan git commitversion-generation-part
, is, as a whole, where we set a versioncmd/cmd.go
, is where we declare version variable and set special comment//go:generate go run gen.go
cmd/gen.go
, is the code that is run bygo:generate
and contains the template forversion.go
cmd/version.go
, is the file that generated bygo:generate
Here are the general overview of using go generate to set version during build process:
- before we run
go build
, we rungo generate ./...
(see theMakefile
) - sas
OK,
I think that’s all for now. Hopefully this tutorial will be helpful for others.
Thanks a lot for watching. Have a great day. See you.
comments powered by Disqus