-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (41 loc) · 1.16 KB
/
main.go
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
package main
import (
"fmt"
"github.com/hollson/gdk/inspect"
)
var (
name string = "test"
version string = "v1.0"
)
/*
演示示例:
构建:
go build -ldflags \
"-X 'main.name=example'
-X 'main.version=V1.0.0'
-X 'github.com/hollson/gdk/inspect.built=$(date "+%Y-%m-%d %H:%M:%S")'
-X 'github.com/hollson/gdk/inspect.branch=$(git rev-parse --abbrev-ref @{u})'" \
-o ./example
运行:
go run -ldflags \
"-X 'main.name=example'
-X 'main.version=V1.0.0'
-X 'github.com/hollson/gdk/inspect.built=$(date "+%Y-%m-%d %H:%M:%S")'
-X 'github.com/hollson/gdk/inspect.branch=$(git rev-parse --abbrev-ref @{u})'
-X 'github.com/hollson/gdk/inspect.commit=$(git rev-parse --short HEAD)'
-X 'github.com/hollson/gdk/inspect.author=$(git config user.name)'
-X 'github.com/hollson/gdk/inspect.tag=$(git describe --tags --abbrev=0)'
-X 'github.com/hollson/gdk/inspect.environment=develop'" \
main.go
*/
func main() {
// 项目私有元信息
fmt.Printf("%s_%s\n\n", name, version)
fmt.Println()
// 通用编译信息
fmt.Println("文本格式:")
fmt.Println(inspect.Info())
fmt.Println()
fmt.Println("Json格式:")
fmt.Println(inspect.Info().Json())
}