Skip to content

Commit

Permalink
feat: add version info
Browse files Browse the repository at this point in the history
  • Loading branch information
elvizlai committed Oct 12, 2017
1 parent 4aeb59a commit 85c7067
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
version=$(shell git rev-parse --short HEAD)

idl:
rm -rf pb/*.pb.go
protoc -I=. pb/*.proto --go_out=plugins=grpc:.

bin:
rm -rf exec_bin
mkdir exec_bin
go build -ldflags "-s -w" -o ./exec_bin/client ./client/*.go
go build -ldflags "-s -w" -o ./exec_bin/server ./server/*.go
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=$(version)" -o ./exec_bin/server-darwin ./server/*.go
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=$(version)" -o ./exec_bin/client-darwin ./client/*.go
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=$(version)" -o ./exec_bin/server-linux ./server/*.go
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=$(version)" -o ./exec_bin/client-linux ./client/*.go


13 changes: 12 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package main
import (
"flag"
"net"
"os"
"runtime"
"time"

"../lib"
"../pb"
"../log"
"../pb"

"golang.org/x/net/context"
"google.golang.org/grpc"
Expand All @@ -16,14 +18,23 @@ import (
var addr = ":50050"
var remoteAddr = ""
var debug bool
var showVersion bool

var version = "self-build"

func init() {
flag.StringVar(&addr, "l", addr, "listen addr")
flag.StringVar(&remoteAddr, "r", remoteAddr, "remote addr")
flag.BoolVar(&debug, "d", false, "debug mode")
flag.BoolVar(&showVersion, "v", false, "show version then exist")

flag.Parse()

if showVersion {
log.Infof("version: %s, using: %s", version, runtime.Version())
os.Exit(0)
}

if remoteAddr == "" {
log.Fatalf("remote addr can not be empty")
}
Expand Down
13 changes: 12 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@ package main
import (
"flag"
"net"
"os"
"runtime"

"../lib"
"../pb"
"../log"
"../pb"

"google.golang.org/grpc"
)

var addr = ":50051"
var debug = false
var showVersion bool

var version = "self-build"

func init() {
flag.StringVar(&addr, "l", addr, "listen addr")
flag.BoolVar(&debug, "d", debug, "debug mode")
flag.BoolVar(&showVersion, "v", false, "show version then exist")

flag.Parse()

if showVersion {
log.Infof("version: %s, using: %s", version, runtime.Version())
os.Exit(0)
}

if debug {
log.SetDebugMode()
}
Expand Down

0 comments on commit 85c7067

Please sign in to comment.