mirror-nourybot/pkg/api/randomcat.go

30 lines
476 B
Go
Raw Normal View History

2021-10-18 14:20:42 +02:00
package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type randomCatResponse struct {
File string `json:"file"`
}
func RandomCat() string {
response, err := http.Get("https://aws.random.cat/meow")
if err != nil {
log.Fatalln(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
}
var responseObject randomCatResponse
json.Unmarshal(responseData, &responseObject)
return string(responseObject.File)
}