summaryrefslogtreecommitdiff
path: root/internal/version
diff options
context:
space:
mode:
Diffstat (limited to 'internal/version')
-rw-r--r--internal/version/version.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/version/version.go b/internal/version/version.go
new file mode 100644
index 0000000..35136d4
--- /dev/null
+++ b/internal/version/version.go
@@ -0,0 +1,20 @@
+package version
+
+import "runtime/debug"
+
+// Version returns the VCS commit hash embedded by `go build`, or "dev" if unavailable.
+func Version() string {
+ info, ok := debug.ReadBuildInfo()
+ if !ok {
+ return "dev"
+ }
+ for _, s := range info.Settings {
+ if s.Key == "vcs.revision" {
+ if len(s.Value) > 8 {
+ return s.Value[:8]
+ }
+ return s.Value
+ }
+ }
+ return "dev"
+}