internal/generator/gemoji.go (view raw)
1package main
2
3import "encoding/json"
4
5const gemojiURL = "https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json"
6
7type gemoji struct {
8 Emoji string `json:"emoji"`
9 Aliases []string `json:"aliases"`
10}
11
12func fetchGemojis() (map[string]string, error) {
13 b, err := fetchData(gemojiURL)
14 if err != nil {
15 return nil, err
16 }
17
18 var gemojis []gemoji
19 r := make(map[string]string)
20
21 if err = json.Unmarshal(b, &gemojis); err != nil {
22 return nil, err
23 }
24
25 for _, gemoji := range gemojis {
26 for _, alias := range gemoji.Aliases {
27 if len(alias) == 0 || len(gemoji.Emoji) == 0 {
28 continue
29 }
30
31 r[makeAlias(alias)] = gemoji.Emoji
32 }
33 }
34
35 return r, nil
36}