-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
78 lines (73 loc) · 1.84 KB
/
event.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
74
75
76
77
78
package goseismic
import (
"encoding/json"
"log"
"time"
)
// Event represent one information obtained from seismic portal
/*{
"action":"update",
"data":{
"geometry":{
"type":"Point",
"coordinates":[
-121.2,
36.6,
-4.0
]
},
"type":"Feature",
"id":"20201230_0000082",
"properties":{
"lastupdate":"2020-12-30T08:47:00.0Z",
"magtype":"md",
"evtype":"ke",
"lon":-121.2,
"auth":"NC",
"lat":36.6,
"depth":4.0,
"unid":"20201230_0000082",
"mag":2.4,
"time":"2020-12-30T08:45:29.9Z",
"source_id":"934165",
"source_catalog":"EMSC-RTS",
"flynn_region":"CENTRAL CALIFORNIA"
}
}
}
*/
type Event struct {
Action string `json:"action"`
Data struct {
Geometry struct {
Type string `json:"type"`
Coordinates [3]float64 `json:"coordinates"`
} `json:"geometry"`
Type string `json:"type"`
ID string `json:"id"`
Properties struct {
LastUpdate time.Time `json:"lastupdate"`
MagType string `json:"magtype"`
EvType string `json:"evtype"`
Longitude float64 `json:"lon"`
Auth string `json:"auth"`
Latitude float64 `json:"lat"`
Depth float64 `json:"depth"`
UnID string `json:"unid"`
Magnitude float64 `json:"mag"`
Time time.Time `json:"time"`
SourceID string `json:"source_id"`
SourceCatalog string `json:"source_catalog"`
FlynnRegion string `json:"flynn_region"`
} `json:"properties"`
} `json:"data"`
}
// ParseEvent converts received message from websocket to Event struct
func ParseEvent(data []byte) (Event, error) {
var event Event
if err := json.Unmarshal(data, &event); err != nil {
log.Println("Error parsing JSON")
return event, err
}
return event, nil
}