2021-10-20 17:27:00 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type randomDuckResponse struct {
|
|
|
|
Url string `json:"url"`
|
|
|
|
}
|
|
|
|
|
2021-10-20 23:21:13 +02:00
|
|
|
// RandomDuck returns a link to a random duck picture.
|
|
|
|
// API used: https://random-d.uk/api/random
|
2021-10-20 17:27:00 +02:00
|
|
|
func RandomDuck() string {
|
|
|
|
response, err := http.Get("https://random-d.uk/api/random")
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
responseData, err := ioutil.ReadAll(response.Body)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var responseObject randomDuckResponse
|
|
|
|
json.Unmarshal(responseData, &responseObject)
|
|
|
|
|
|
|
|
return string(responseObject.Url)
|
|
|
|
}
|