Skip to content

Commit

Permalink
Print build-time of the binary and version (--version).
Browse files Browse the repository at this point in the history
Add couple of makefile targets.
  • Loading branch information
nsimariaj committed Apr 24, 2018
1 parent 6df91b5 commit 5b6ac32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

all: run

LDFLAGS=--ldflags="-X main.Version=`git rev-list -1 HEAD` -X main.BuildTime=`date +%FT%T%z`"
build-mac:
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o jtimon-darwin-amd64
build-linux:
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o jtimon-linux-amd64

build:
docker build -t jtimon .
ln -sf launch-docker-container.sh jtimon
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"strconv"
Expand All @@ -21,6 +22,7 @@ var (
gnmiEncoding = flag.String("gnmi-encoding", "proto", "gnmi encoding (proto | json | bytes | ascii | ietf-json")
logFile = flag.String("log", "", "Log file name")
gtrace = flag.Bool("gtrace", false, "Collect GRPC traces")
version = flag.Bool("version", false, "Print version and build-time of the binary and exit")
gnmi = flag.Bool("gnmi", false, "Use gnmi proto")
td = flag.Bool("time-diff", false, "Time Diff for sensor analysis using InfluxDB")
dcheck = flag.Bool("drop-check", false, "Check for packet drops")
Expand All @@ -37,6 +39,11 @@ var (
st statsType
)

var (
Version = "version-not-available"
BuildTime = "build-time-not-available"
)

type jcontext struct {
cfg config
dMap map[uint32]map[uint32]map[string]dropData
Expand All @@ -50,6 +57,13 @@ type jcontext struct {
func main() {
st.startTime = time.Now()
flag.Parse()
if *version {
fmt.Println("Version: ", Version)
fmt.Println("BuildTime: ", BuildTime)
return
}
fmt.Println("Version: ", Version)
fmt.Println("BuildTime: ", BuildTime)

jctx := jcontext{}
jctx.cfg = configInit(*cfgFile)
Expand Down

0 comments on commit 5b6ac32

Please sign in to comment.