-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathversion.go
More file actions
58 lines (46 loc) · 991 Bytes
/
Copy pathversion.go
File metadata and controls
58 lines (46 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"fmt"
"os"
"runtime/debug"
)
// these information will be collected when build, by `-ldflags "-X main.appVersion=0.0.1"`
const (
defaultAppVersion = "0.0.0"
textLogo = `
_____ ____ _ ____ ________ _
/ __// _ \ / \ |\/_ \/ __/\ \//
| | _| / \|_____ | | // / /| \ \ /
| |_//| \_/|\____\| \// / /_| /_ / \
\____\\____/ \__/ \____/\____\/__/\\
`
)
var (
appVersion = defaultAppVersion
)
func init() {
rebuildAppVersion()
var (
versionFlag = flag.Bool("version", false, "显示版本号")
msg = fmt.Sprintf("%s \nversion %s", textLogo, appVersion)
)
flag.Parse()
if *versionFlag {
fmt.Println(msg)
os.Exit(0)
}
}
func rebuildAppVersion() {
if appVersion != defaultAppVersion {
return
}
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
if info.Main.Version == "(devel)" {
return
}
appVersion = info.Main.Version
}