summaryrefslogtreecommitdiffhomepage
path: root/internal/version/version.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/version/version.go')
-rw-r--r--internal/version/version.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/version/version.go b/internal/version/version.go
new file mode 100644
index 000000000..54c576f6c
--- /dev/null
+++ b/internal/version/version.go
@@ -0,0 +1,25 @@
+package version
+
+import "runtime/debug"
+
+// Build-time parameters set via -ldflags
+var Version = "unknown"
+
+// A user may install pug using `go install github.com/leg100/pug@latest`
+// without -ldflags, in which case the version above is unset. As a workaround
+// we use the embedded build version that *is* set when using `go install` (and
+// is only set for `go install` and not for `go build`).
+func init() {
+ info, ok := debug.ReadBuildInfo()
+ if !ok {
+ // < go v1.18
+ return
+ }
+ mainVersion := info.Main.Version
+ if mainVersion == "" || mainVersion == "(devel)" {
+ // bin not built using `go install`
+ return
+ }
+ // bin built using `go install`
+ Version = mainVersion
+}