-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion.go
44 lines (36 loc) · 856 Bytes
/
region.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
package radicron
import (
"encoding/xml"
"io"
"net/http"
)
type XMLRegion struct {
Region []XMLRegionStations `xml:"stations"`
}
type XMLRegionStations struct {
Stations []XMLRegionStation `xml:"station"`
RegionID string `xml:"region_id,attr"`
RegionName string `xml:"region_name,attr"`
}
type XMLRegionStation struct {
ID string `xml:"id"`
Name string `xml:"name"`
AreaID string `xml:"area_id"`
Ruby string `xml:"ruby"`
}
func FetchXMLRegion() (XMLRegion, error) {
region := XMLRegion{}
resp, err := http.Get(APIRegionFull) //nolint:noctx
if err != nil {
return region, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return region, err
}
if err := xml.Unmarshal([]byte(string(body)), ®ion); err != nil {
return region, err
}
return region, nil
}