-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstations.go
45 lines (37 loc) · 1.05 KB
/
stations.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
package noaa
import (
"encoding/json"
"encoding/xml"
"fmt"
)
type Stations struct {
XMLName xml.Name `xml:"stations"`
Stations []Station `xml:"station"`
}
type Station struct {
XMLName xml.Name `xml:"station"`
ID string `xml:"id,attr"`
Lat float32 `xml:"lat,attr"`
Lon float32 `xml:"lon,attr"`
Name string `xml:"name,attr"`
Owner string `xml:"owner,attr"`
Type string `xml:"type,attr"`
Met string `xml:"met,attr"`
Currents string `xml:"currents,attr"`
WaterQuality string `xml:"waterquality,attr"`
}
// func (s Station) String() string {
// return fmt.Sprintf("(Station id=%s, name=%s, lat=%f, lon=%f)",
// s.ID, s.Name, s.Lat, s.Lon,
// )
// }
func GetActiveStations() string {
url := fmt.Sprintf("%s.%s", ActiveStations, "xml")
response := request(url)
var activeStations Stations
if err := xml.Unmarshal(response, &activeStations); err != nil {
panic(err)
}
activeStationsJson, _ := json.Marshal(activeStations)
return string(activeStationsJson)
}