-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathircity.go
44 lines (40 loc) · 801 Bytes
/
ircity.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 goircity
// Provinces get provinces list.
func Provinces() []IrProvince {
res := make([]IrProvince, 0)
for _, prov := range provinces {
res = append(res, prov)
}
return res
}
// FindProvince find province by code.
func FindProvince(code uint) *IrProvince {
prov, ok := provinces[code]
if ok {
return &prov
} else {
return nil
}
}
// Cities get city list for province.
func Cities(province uint) []IrCity {
res := make([]IrCity, 0)
for _, city := range cities {
if city.ProvinceCode == province {
res = append(res, city)
}
}
return res
}
// FindProvince find city by code.
func FindCity(code uint) *IrCity {
city, ok := cities[code]
if ok {
province, ok := provinces[city.ProvinceCode]
if ok {
city.Province = &province
}
return &city
}
return nil
}