Skip to content

Commit 9b6c7ec

Browse files
committed
add build with ldflags
1 parent 1680121 commit 9b6c7ec

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ intra/
2020
nbn/
2121
mocks/*
2222
.vscode
23-
schema-dir
23+
schema-dir
24+
dist/

.goreleaser.nightlies.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ builds:
44
binary: data-server
55
env:
66
- CGO_ENABLED=0
7+
ldflags:
8+
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}}
79
goos:
810
- linux
911
goarch:

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ builds:
44
binary: data-server
55
env:
66
- CGO_ENABLED=0
7+
ldflags:
8+
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}}
79
goos:
810
- linux
911
goarch:

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ var debug bool
2121
var trace bool
2222
var stop bool
2323

24+
var versionFlag bool
25+
var version = "dev"
26+
var commit = ""
27+
2428
func main() {
2529
pflag.StringVarP(&configFile, "config", "c", "", "config file path")
2630
pflag.BoolVarP(&debug, "debug", "d", false, "set log level to DEBUG")
2731
pflag.BoolVarP(&trace, "trace", "t", false, "set log level to TRACE")
32+
pflag.BoolVarP(&versionFlag, "version", "v", false, "print version")
2833
pflag.Parse()
2934

35+
if versionFlag {
36+
fmt.Println(version + "-" + commit)
37+
return
38+
}
39+
3040
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
3141
log.SetLevel(log.InfoLevel)
3242
if debug {

0 commit comments

Comments
 (0)