/
messages.go
59 lines (54 loc) · 1.16 KB
/
messages.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
package marketwatch
import (
"github.com/antihax/goesi/esi"
)
// Message wraps different payloads for the websocket interface
type Message struct {
Action string `json:"action"`
Payload interface{} `json:"payload"`
}
func (s *MarketWatch) dumpMarket(channels map[string]bool, send chan interface{}) {
// Prevent changes to the map while we loop
s.mmutex.RLock()
defer s.mmutex.RUnlock()
// loop all the locations
if channels["market"] {
for _, r := range s.market {
// Build a list
m := []esi.GetMarketsRegionIdOrders200Ok{}
r.Range(
func(k, v interface{}) bool {
o := v.(Order)
m = append(m, o.Order)
return true
})
// send the list out
if len(m) > 0 {
send <- Message{
Action: "addition",
Payload: m,
}
}
}
}
// loop all the locations
if channels["contract"] {
for _, r := range s.contracts {
// Build a list
m := []FullContract{}
r.Range(
func(k, v interface{}) bool {
o := v.(Contract)
m = append(m, o.Contract)
return true
})
// send the list out
if len(m) > 0 {
send <- Message{
Action: "contractAddition",
Payload: m,
}
}
}
}
}