-
Notifications
You must be signed in to change notification settings - Fork 0
/
volcano.go
56 lines (43 loc) · 1.17 KB
/
volcano.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
package geonet
// Volcano represents a volcano status
type Volcano struct {
volcanoProperties
Coordinates []float64 `json:"coordinates"`
}
// Volcanos will return a list containing the status of
// all volcanos in the Zelandian continent
func (c *Client) Volcanos() ([]Volcano, error) {
resp := volcanoAPIResponse{}
if err := c.Get("/volcano/val", &resp); err != nil {
return []Volcano{}, err
}
return resp.Volcanos(), nil
}
type volcanoProperties struct {
// a unique identifier for the volcano
ID string `json:"volcanoID"`
// the volcano title
Title string `json:"volcanoTitle"`
// volcanic alert level
Level int `json:"level"`
// volcanic activity
Activity string `json:"activity"`
// most likely hazards
Hazards string `json:"hazards"`
}
type volcanoFeature struct {
feature
Properties volcanoProperties `json:"properties"`
}
type volcanoAPIResponse struct {
Type string `json:"type"`
Features []volcanoFeature `json:"features"`
}
func (res volcanoAPIResponse) Volcanos() []Volcano {
reports := []Volcano{}
for _, f := range res.Features {
r := Volcano{f.Properties, f.Geometry.Coordinates}
reports = append(reports, r)
}
return reports
}