-2

I am researching approaches to organize projects in different open source projects (for example operator-framework/operator-sdk) and sometime find version package with version.go file:

├── build
├── cmd
├── deploy
├── go.mod
├── go.sum
├── pkg
├── tools.go
└── version
    └── version.go

package version

var (
    Version = "0.0.1"
)

I tried to find how to use it to control application version, but found only approach uses -ldflags.

Are exist other ways to use version package and version.go file?

kozmo
  • 4,024
  • 3
  • 30
  • 48

1 Answers1

2

Are exists other ways to use version package and version.go file?

No.

Volker
  • 40,468
  • 7
  • 81
  • 87
  • How can I get `Version` value from `app` (except of `fmt.Print(...)`)? – kozmo Apr 24 '20 at 07:22
  • 1
    You cannot. Go binaries do not have per se a "version". They are just binaries which might or might not know and/or expose their "version". – Volker Apr 24 '20 at 08:51
  • that's mean if I want to maintain version of binaries I have to set "version" into `var` use `-ldflags` when I build app and then get "version" from binaries use own implemented mechanism (for example `CLI` implemented with `cobra` library)?! – kozmo Apr 24 '20 at 09:23
  • 1
    Yes, this is one possible way. A `version` variable set during build time via -ldflags and a `-version` flag printing `version` is common. Other things are possible too. – Volker Apr 24 '20 at 13:56