Skip to content

Commit ba97af9

Browse files
committed
feat: support dynamic version
1 parent dd871c8 commit ba97af9

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

version.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616

1717
package main
1818

19-
const (
20-
Version = "0.2.1"
19+
import (
20+
"debug/buildinfo"
21+
"fmt"
22+
"os"
2123
)
24+
25+
var Version = "0.0.0"
26+
27+
func init() {
28+
path, err := os.Executable()
29+
if err != nil {
30+
fmt.Fprintf(os.Stderr, "fail to get executable path: %v\n", err)
31+
return
32+
}
33+
data, err := os.Open(path)
34+
if err != nil {
35+
fmt.Fprintf(os.Stderr, "fail to read executable file: %v\n", err)
36+
return
37+
}
38+
info, err := buildinfo.Read(data)
39+
if err != nil {
40+
fmt.Fprintf(os.Stderr, "fail to read build info: %v\n", err)
41+
return
42+
}
43+
Version = info.Main.Version
44+
}

0 commit comments

Comments
 (0)