2021-10-18 14:31:44 +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:31:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type randomFoxResponse struct {
|
|
|
|
Image string `json:"image"`
|
|
|
|
Link string `json:"link"`
|
|
|
|
}
|
|
|
|
|
2021-10-20 23:21:13 +02:00
|
|
|
// RandomFox returns a link to a random fox picture.
|
|
|
|
// API used: https://randomfox.ca/floof/
|
2021-10-18 14:31:44 +02:00
|
|
|
func RandomFox() string {
|
|
|
|
response, err := http.Get("https://randomfox.ca/floof/")
|
|
|
|
if err != nil {
|
2021-10-19 15:33:23 +02:00
|
|
|
log.Error(err)
|
2021-10-18 14:31:44 +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:31:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var responseObject randomFoxResponse
|
|
|
|
json.Unmarshal(responseData, &responseObject)
|
|
|
|
|
|
|
|
return string(responseObject.Image)
|
|
|
|
}
|