Skip to content

Commit

Permalink
feat: app version from compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkEzz committed Dec 30, 2021
1 parent 9a2fdce commit 4b26163
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
database/local.db
database/local.db
sattrack
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ifndef VERSION
VERSION := $(shell git describe --always --tags)
endif

DATE := $(shell date -u +%Y%m%d.%H%M%S)

LDFLAGS = -ldflags "-X=main.Version=$(VERSION)-$(DATE)"

.PHONY: sattrack clean

.DEFAULT_GOAL := sattrack

sattrack:
go build $(LDFLAGS)

clean:
rm -f sattrack
4 changes: 2 additions & 2 deletions handlers/TrackingHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func HandleWsTracking(c *websocket.Conn, db *gorm.DB) {
observation := sgp4.ObservationFromLocation(lat, lng, alt)
if err := c.WriteJSON(observation); err != nil {
// error
break
return
}
time.Sleep(time.Millisecond * 500)
time.Sleep(time.Second)
}
}

Expand Down
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"log"

"github.com/SharkEzz/sattrack/database"
"github.com/SharkEzz/sattrack/handlers"
Expand All @@ -12,12 +13,18 @@ import (
"github.com/gofiber/websocket/v2"
)

const (
AppName = "SatTrack"
)

var (
shouldUpdate = flag.Bool("update", false, "Use this flag to update all the TLE")
Version = "no_version"
)

func main() {
flag.Parse()

db := database.Init("database/local.db")

validator := validator.New()
Expand All @@ -26,7 +33,9 @@ func main() {
services.UpdateDatabase(db)
}

app := fiber.New()
app := fiber.New(fiber.Config{
DisableStartupMessage: true,
})

app.Use("/ws", func(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
Expand All @@ -36,6 +45,10 @@ func main() {
return fiber.ErrUpgradeRequired
})

app.Get("/", func(c *fiber.Ctx) error {
return c.SendString(AppName)
})

app.Post("/tracking", func(c *fiber.Ctx) error {
return handlers.HandlePostTracking(c, db, validator)
})
Expand All @@ -44,5 +57,6 @@ func main() {
handlers.HandleWsTracking(c, db)
}))

log.Println("Started", AppName, Version)
app.Listen(":8000")
}
2 changes: 1 addition & 1 deletion validation/Tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func ValidateWebsocketQuery(c *websocket.Conn) (int, float64, float64, float64, error) {
var (
qCatNbr = c.Query("catNbr")
qCatNbr = c.Query("catnbr")
qLat = c.Query("lat")
qLng = c.Query("lng")
qAlt = c.Query("alt")
Expand Down

0 comments on commit 4b26163

Please sign in to comment.