mirror-nourybot/pkg/api/randomcat.go

31 lines
500 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"`
}
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)
}