-
Notifications
You must be signed in to change notification settings - Fork 5
/
user_tags.go
45 lines (36 loc) · 878 Bytes
/
user_tags.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 geonames
import (
"log"
"strconv"
)
const userTagsURL = `userTags.zip`
// UserTags returns all available user tags for any objects of the system
func (c *Client) UserTags() (map[int][]string, error) {
var err error
zipped, err := c.httpGet(geonamesURL + userTagsURL)
if err != nil {
return nil, err
}
unzipped, err := unzip(zipped)
if err != nil {
return nil, err
}
data, err := getZipData(unzipped, "userTags.txt")
if err != nil {
return nil, err
}
result := make(map[int][]string)
parse(data, 0, func(raw [][]byte) bool {
if len(raw) != 2 {
return true
}
geonameID, err := strconv.Atoi(string(raw[0]))
if err != nil {
log.Printf("while parsing user tag geoname id %s: %s", string(raw[0]), err.Error())
return true
}
result[geonameID] = append(result[geonameID], string(raw[1]))
return true
})
return result, nil
}