mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
31 lines
503 B
Go
31 lines
503 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type randomDuckResponse struct {
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
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)
|
|
}
|