|
|
@@ -48,7 +48,7 @@ func main() { |
|
|
alertsReader := appState.AddKafkaReader(cfg.KafkaURL, "alertbeacons", "gid-alert-serv") |
|
|
alertsReader := appState.AddKafkaReader(cfg.KafkaURL, "alertbeacons", "gid-alert-serv") |
|
|
|
|
|
|
|
|
client := appState.AddValkeyClient(cfg.ValkeyURL) |
|
|
client := appState.AddValkeyClient(cfg.ValkeyURL) |
|
|
// Need Lua script to pull all of the beacons in one go on init |
|
|
|
|
|
|
|
|
fmt.Println("Init of kafka writers and readers done") |
|
|
|
|
|
|
|
|
chLoc := make(chan model.HTTPLocation, 200) |
|
|
chLoc := make(chan model.HTTPLocation, 200) |
|
|
chEvents := make(chan model.BeaconEvent, 500) |
|
|
chEvents := make(chan model.BeaconEvent, 500) |
|
|
@@ -59,6 +59,8 @@ func main() { |
|
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
r := mux.NewRouter() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("new print") |
|
|
|
|
|
fmt.Println("new print") |
|
|
// For now just add beacon DELETE / GET / POST / PUT methods |
|
|
// For now just add beacon DELETE / GET / POST / PUT methods |
|
|
r.HandleFunc("/api/beacons/{beacon_id}", controller.BeaconsDeleteController(writer, ctx, appState)).Methods("DELETE") |
|
|
r.HandleFunc("/api/beacons/{beacon_id}", controller.BeaconsDeleteController(writer, ctx, appState)).Methods("DELETE") |
|
|
r.HandleFunc("/api/beacons", controller.BeaconsListController(appState)).Methods("GET") |
|
|
r.HandleFunc("/api/beacons", controller.BeaconsListController(appState)).Methods("GET") |
|
|
@@ -69,9 +71,14 @@ func main() { |
|
|
r.HandleFunc("/api/settings", controller.SettingsListController(appState, client, ctx)).Methods("GET") |
|
|
r.HandleFunc("/api/settings", controller.SettingsListController(appState, client, ctx)).Methods("GET") |
|
|
r.HandleFunc("/api/settings", controller.SettingsEditController(settingsWriter, appState, client, ctx)).Methods("POST") |
|
|
r.HandleFunc("/api/settings", controller.SettingsEditController(settingsWriter, appState, client, ctx)).Methods("POST") |
|
|
|
|
|
|
|
|
r.HandleFunc("/api/beacons/ws", serveWs(appState, ctx)) |
|
|
|
|
|
|
|
|
// r.HandleFunc("/api/beacons/ws", serveWs(appState, ctx)) |
|
|
|
|
|
|
|
|
http.ListenAndServe(cfg.HTTPAddr, handlers.CORS(originsOk, headersOk, methodsOk)(r)) |
|
|
|
|
|
|
|
|
server := http.Server{ |
|
|
|
|
|
Addr: cfg.HTTPAddr, |
|
|
|
|
|
Handler: handlers.CORS(originsOk, headersOk, methodsOk)(r), |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go server.ListenAndServe() |
|
|
|
|
|
|
|
|
eventLoop: |
|
|
eventLoop: |
|
|
for { |
|
|
for { |
|
|
@@ -89,7 +96,11 @@ eventLoop: |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fmt.Println("broken out of the main event loop") |
|
|
|
|
|
|
|
|
if err := server.Shutdown(context.Background()); err != nil { |
|
|
|
|
|
fmt.Printf("could not shutdown: %v\n", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("broken out of the main event loop and HTTP server shutdown") |
|
|
wg.Wait() |
|
|
wg.Wait() |
|
|
|
|
|
|
|
|
fmt.Println("All go routines have stopped, Beggining to close Kafka connections") |
|
|
fmt.Println("All go routines have stopped, Beggining to close Kafka connections") |
|
|
@@ -151,7 +162,9 @@ func writer(ws *websocket.Conn, appstate *appcontext.AppState, ctx context.Conte |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func reader(ws *websocket.Conn) { |
|
|
func reader(ws *websocket.Conn) { |
|
|
defer ws.Close() |
|
|
|
|
|
|
|
|
defer func() { |
|
|
|
|
|
ws.Close() |
|
|
|
|
|
}() |
|
|
ws.SetReadLimit(512) |
|
|
ws.SetReadLimit(512) |
|
|
ws.SetReadDeadline(time.Now().Add((60 * 9) / 10 * time.Second)) |
|
|
ws.SetReadDeadline(time.Now().Add((60 * 9) / 10 * time.Second)) |
|
|
ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add((60 * 9) / 10 * time.Second)); return nil }) |
|
|
ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add((60 * 9) / 10 * time.Second)); return nil }) |
|
|
|