-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
58 lines (50 loc) · 1.13 KB
/
events.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
package relayergosdk
import (
"encoding/json"
)
type DataFeed struct {
Event string `json:"event"`
Price string `json:"p"`
FeedID string `json:"feedID"`
T int64 `json:"t"`
}
type SubscriptionFeed struct {
FeedID string `json:"feedID"`
Type string `json:"type"`
}
type SubscriptionMsg struct {
Event string `json:"event"`
Success []SubscriptionFeed `json:"success"`
Error []SubscriptionFeed `json:"error"`
}
type event struct {
Event string `json:"event"`
}
func sendEvent(data []byte, priceFeedChan chan<- DataFeed, subscriptionMsgChan chan<- SubscriptionMsg) error {
res := event{}
err := json.Unmarshal(data, &res)
if err != nil {
return err
}
switch res.Event {
case "price":
var priceFeed DataFeed
err := json.Unmarshal(data, &priceFeed)
if err != nil {
return err
}
priceFeedChan <- priceFeed
case "subscribe-status":
var subscriptionMsg SubscriptionMsg
err := json.Unmarshal(data, &subscriptionMsg)
if err != nil {
return err
}
subscriptionMsgChan <- subscriptionMsg
case "subscribe-failed":
return &SubscribeFailed{}
default:
return &InvalidEvent{}
}
return nil
}