-
Notifications
You must be signed in to change notification settings - Fork 2
/
stationInfo.go
43 lines (36 loc) · 1014 Bytes
/
stationInfo.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
package main
import (
"database/sql"
"github.com/PiotrTopa/js8web/model"
)
var stationInfoCache model.StationInfoWsEvent = model.StationInfoWsEvent{}
func stationInfoNotifier(event *model.Js8callEvent, websocketEvents chan<- model.WebsocketEvent, databaseObjects chan<- model.DbObj) error {
newStationInfo := stationInfoCache
err := newStationInfo.UpdateFromEvent(event)
if err != nil {
logger.Sugar().Errorw(
"Can not undertand StationInfo event",
"event", event,
"error", err,
)
return nil
}
if newStationInfo != stationInfoCache {
stationInfoCache = newStationInfo
websocketEvents <- &stationInfoCache
stationInfoObj := model.CreateStationInfoObj(stationInfoCache)
databaseObjects <- stationInfoObj
}
return nil
}
func initStationInfoCache(db *sql.DB) {
stationInfo, err := model.FetchLatestStationInfo(db)
if err != nil {
logger.Sugar().Warnw(
"Can not initialize StationInfo",
"error", err,
)
return
}
stationInfoCache = stationInfo.StationInfoWsEvent
}