mirror-nourybot/pkg/api/randomcat.go
2021-10-20 23:21:13 +02:00

33 lines
594 B
Go

package api
import (
"encoding/json"
"io/ioutil"
"net/http"
log "github.com/sirupsen/logrus"
)
type randomCatResponse struct {
File string `json:"file"`
}
// RandomCat returns a link to a random cat picture.
// API used: https://aws.random.cat/meow
func RandomCat() string {
response, err := http.Get("https://aws.random.cat/meow")
if err != nil {
log.Error(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Error(err)
}
var responseObject randomCatResponse
json.Unmarshal(responseData, &responseObject)
return string(responseObject.File)
}