-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (56 loc) · 1.56 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"flag"
"log"
"github.com/SharkEzz/sattrack/database"
"github.com/SharkEzz/sattrack/handlers"
"github.com/SharkEzz/sattrack/services"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"
)
const (
appName string = "SatTrack"
)
var (
shouldUpdate = flag.Bool("update", false, "Use this flag to update all the TLE")
tleListURL = flag.String("tleUrl", "https://celestrak.com/NORAD/elements/active.txt", "default URL to fetch TLEs")
version = "devel"
)
func main() {
log.Println("Starting", appName, version)
flag.Parse()
db := database.Init("./data/local.db")
if *shouldUpdate {
services.UpdateDatabase(*tleListURL, db)
} else {
log.Println("Not updating TLE database (flag -update not given)")
}
log.Println("Loaded", services.GetTLECount(db), "TLEs")
validator := validator.New()
app := fiber.New(fiber.Config{
DisableStartupMessage: true,
AppName: appName,
})
app.Use("/ws", func(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
c.Locals("allowed", true)
return c.Next()
}
return fiber.ErrUpgradeRequired
})
apiGroup := app.Group("/api")
apiGroup.Post("/tracking", func(c *fiber.Ctx) error {
return handlers.HandlePostTracking(c, db, validator)
})
app.Get("/ws/tracking", websocket.New(func(c *websocket.Conn) {
handlers.HandleWsTracking(c, db)
}))
// SPA
app.Static("/", "public")
app.Get("*", func(c *fiber.Ctx) error {
return c.SendFile("public/index.html")
})
log.Println(appName, "ready")
app.Listen(":8000")
}