Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
chenlujjj committed Jan 1, 2022
0 parents commit b68d3b2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
VERSION := $(shell cat VERSION)
BUILD_USER := $(shell whoami)
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT := $(shell git rev-list -1 HEAD)
GIT_SHORT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)


GOLDFLAGS = "-X main.Version=$(VERSION) -X main.GitBranch=$(GIT_BRANCH) -X main.GitCommit=$(GIT_COMMIT) -X main.BuildUser=$(BUILD_USER) -X main.BuildDate=$(BUILD_DATE)"

build:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags $(GOLDFLAGS) -o main
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"flag"
"fmt"
"runtime"
)

func main() {
versionFlag := flag.Bool("version", false, "Print version information and quit")
flag.Parse()
if *versionFlag {
printVersion()
}
}

var (
Version string
GitBranch string
GitCommit string
BuildUser string
BuildDate string
)

func printVersion() {
fmt.Printf(`version %s
build user: %s
build date: %s
go version: %s
platform: %s/%s
git branch: %s
git commit: %s
`, Version, BuildUser, BuildDate, runtime.Version(), runtime.GOOS, runtime.GOARCH, GitBranch, GitCommit)
}

0 comments on commit b68d3b2

Please sign in to comment.