-
Notifications
You must be signed in to change notification settings - Fork 0
/
meme.go
38 lines (36 loc) · 953 Bytes
/
meme.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
//"image"
//"image/gif"
//"golang.org/x/image/font"
)
func getMeme(search string) string {
var media string
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
media = ""
}
}()
var response map[string]interface{}
escaped := url.PathEscape(search)
url := fmt.Sprintf("https://api.tenor.com/v1/search?q=%s&key=%s&limit=1", escaped, tenorKey)
fmt.Println(url)
res, err := http.Get(url)
if err != nil {
panic(fmt.Errorf("Tenor request failed: %s", err))
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(fmt.Errorf("Parse error: %s", err))
}
json.Unmarshal(body, &response)
fmt.Println(response)
media = response["results"].([]interface{})[0].(map[string]interface{})["media"].([]interface{})[0].(map[string]interface{})["gif"].(map[string]interface{})["url"].(string) //jesus christ what the fuck
return media
}