mirror-nourybot/pkg/api/randomcat.go

33 lines
594 B
Go
Raw Normal View History

2021-10-18 14:20:42 +02:00
package api
import (
"encoding/json"
"io/ioutil"
"net/http"
2021-10-19 15:33:23 +02:00
log "github.com/sirupsen/logrus"
2021-10-18 14:20:42 +02:00
)
type randomCatResponse struct {
File string `json:"file"`
}
2021-10-20 23:21:13 +02:00
// RandomCat returns a link to a random cat picture.
// API used: https://aws.random.cat/meow
2021-10-18 14:20:42 +02:00
func RandomCat() string {
response, err := http.Get("https://aws.random.cat/meow")
if err != nil {
2021-10-19 15:33:23 +02:00
log.Error(err)
2021-10-18 14:20:42 +02:00
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
2021-10-19 15:33:23 +02:00
log.Error(err)
2021-10-18 14:20:42 +02:00
}
var responseObject randomCatResponse
json.Unmarshal(responseData, &responseObject)
return string(responseObject.File)
}