Add version

This commit is contained in:
Simon Eisenmann 2017-05-23 15:08:54 +02:00
parent 958515d6f6
commit 28b27cda81
3 changed files with 29 additions and 6 deletions

View file

@ -6,6 +6,8 @@ GOARCH ?= $(shell go env GOARCH)
GOPKG = github.com/longsleep/realtimetraffic
GOPATH = "$(CURDIR)/vendor:$(CURDIR)"
SYSTEM_GOPATH = /usr/share/gocode/src/
VERSION = $(shell git describe --tags --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo git)
BUILDSTAMP = $(shell date -u '+%Y-%m-%dT%T%z')
DIST := $(PWD)/dist
DIST_SRC := $(DIST)/src
@ -40,7 +42,13 @@ generate-dev:
GOPATH=$(GOPATH) $(CURDIR)/vendor/bin/go-bindata -dev -prefix "client/static/" -pkg client -o client/bindata.go client/static/...; fi
binary-%: generate
GOPATH=$(GOPATH) GOOS=linux GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/realtimetrafficd-$(GOARCH) realtimetrafficd/*.go
GOPATH=$(GOPATH) GOOS=linux GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=0 \
go build \
-ldflags="-s -w \
-X main.Version=$(VERSION) \
-X main.BuildStamp=$(BUILDSTAMP) \
" \
-o bin/realtimetrafficd-$(GOARCH) realtimetrafficd/*.go
binary: binary-$(GOARCH)
mv bin/realtimetrafficd-$(GOARCH) bin/realtimetrafficd

View file

@ -19,16 +19,16 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
"runtime"
"github.com/longsleep/realtimetraffic/client"
"github.com/gorilla/websocket"
)
var listenAddr *string
func serveClient(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" && r.Method != "HEAD" {
http.Error(w, "Method nod allowed", 405)
@ -68,15 +68,26 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
func main() {
var err error
listenAddr = flag.String("listen", "127.0.0.1:8088", "Listen address.")
listenAddr := flag.String("listen", "127.0.0.1:8088", "Listen address.")
versionFlag := flag.Bool("version", false, "Version")
flag.Parse()
if *versionFlag {
fmt.Println("Version :", Version)
fmt.Println("Build time :", BuildStamp)
fmt.Println("Go :", runtime.Version())
return
}
go h.run()
http.HandleFunc("/", serveClient)
http.HandleFunc("/realtimetraffic", serveWs)
log.Printf("starting realtimetrafficd %s on %sn", Version, *listenAddr)
err = http.ListenAndServe(*listenAddr, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
log.Fatal(err.Error())
}
defer log.Println("exiting")
}

View file

@ -0,0 +1,4 @@
package main
var Version = "0.0.0"
var BuildStamp = "not set"