File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change 11package version
22
3- // These variables will be set during build time
3+ import "runtime/debug"
4+
5+ // These variables will be set during build time via ldflags.
6+ // When installed via `go install`, they fall back to Go's embedded module info.
47var (
5- // Version is the current version of the application
6- Version = "dev"
7- // Commit is the git commit SHA at build time
8- Commit = "none"
9- // BuildDate is the date when the binary was built
8+ Version = ""
9+ Commit = "none"
1010 BuildDate = "unknown"
1111)
12+
13+ func init () {
14+ if Version != "" {
15+ return
16+ }
17+ info , ok := debug .ReadBuildInfo ()
18+ if ok && info .Main .Version != "" && info .Main .Version != "(devel)" {
19+ Version = info .Main .Version
20+ } else {
21+ Version = "dev"
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments