We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 94ef6f1 commit 595ed07Copy full SHA for 595ed07
1 file changed
version/version.go
@@ -1,11 +1,23 @@
1
package version
2
3
-// These variables will be set during build time
+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.
7
var (
- // Version is the current version of the application
- Version = "dev"
- // Commit is the git commit SHA at build time
8
- Commit = "none"
9
- // BuildDate is the date when the binary was built
+ Version = ""
+ Commit = "none"
10
BuildDate = "unknown"
11
)
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
+}
0 commit comments