-
Notifications
You must be signed in to change notification settings - Fork 4
/
emoji2gist.go
65 lines (55 loc) · 1.13 KB
/
emoji2gist.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"sort"
)
var outfile = flag.String("o", "", "write output to `file`")
func main() {
log.SetFlags(0)
log.SetPrefix("emoji2gist: ")
flag.Parse()
resp, err := http.Get("https://api.github.com/emojis")
if err != nil {
log.Fatal(err)
}
if resp.StatusCode != 200 {
log.Fatal(resp.Status)
}
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
list := make(map[string]string)
err = json.Unmarshal(data, &list)
if err != nil {
log.Fatal(err)
}
var names []string
for name := range list {
names = append(names, name)
}
sort.Strings(names)
var buf bytes.Buffer
fmt.Fprintf(&buf, "code | emoji\n-|-\n")
for _, name := range names {
fmt.Fprintf(&buf, "`%s` | :%s:\n", name, name)
}
if *outfile != "" {
if err := os.WriteFile(*outfile, buf.Bytes(), 0666); err != nil {
log.Fatal(err)
}
} else {
os.Stdout.Write(buf.Bytes())
}
}