2021-10-18 18:33:49 +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 18:33:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type randomDogResponse struct {
|
|
|
|
Url string `json:"url"`
|
|
|
|
}
|
|
|
|
|
2021-10-20 23:21:13 +02:00
|
|
|
// RandomDog returns a link to a random dog picture.
|
|
|
|
// API used: https://random.dog/woof.json
|
2021-10-18 18:33:49 +02:00
|
|
|
func RandomDog() string {
|
|
|
|
response, err := http.Get("https://random.dog/woof.json")
|
|
|
|
if err != nil {
|
2021-10-19 15:33:23 +02:00
|
|
|
log.Error(err)
|
2021-10-18 18:33:49 +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 18:33:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var responseObject randomDogResponse
|
|
|
|
json.Unmarshal(responseData, &responseObject)
|
|
|
|
|
|
|
|
return string(responseObject.Url)
|
|
|
|
}
|