mirror of
https://github.com/longsleep/realtimetraffic.git
synced 2024-11-16 08:48:33 +01:00
Add version
This commit is contained in:
parent
958515d6f6
commit
28b27cda81
3 changed files with 29 additions and 6 deletions
10
Makefile
10
Makefile
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
4
realtimetrafficd/version.go
Normal file
4
realtimetrafficd/version.go
Normal file
|
@ -0,0 +1,4 @@
|
|||
package main
|
||||
|
||||
var Version = "0.0.0"
|
||||
var BuildStamp = "not set"
|
Loading…
Reference in a new issue