This commit is contained in:
lyx0 2021-10-24 17:29:01 +02:00
parent f0a4deaa55
commit 235600ea4d
2 changed files with 5 additions and 1 deletions

View file

@ -15,6 +15,7 @@ func RandomNumber() string {
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
responseData, err := ioutil.ReadAll(response.Body) responseData, err := ioutil.ReadAll(response.Body)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -27,12 +28,15 @@ func RandomNumber() string {
// API used: http://numbersapi.com // API used: http://numbersapi.com
func Number(number string) string { func Number(number string) string {
response, err := http.Get(fmt.Sprint("http://numbersapi.com/" + string(number))) response, err := http.Get(fmt.Sprint("http://numbersapi.com/" + string(number)))
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
responseData, err := ioutil.ReadAll(response.Body) responseData, err := ioutil.ReadAll(response.Body)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
return string(responseData) return string(responseData)
} }

View file

@ -19,6 +19,7 @@ type XkcdResponse struct {
// RandomXkcd returns a link to a random Xkcd comic. // RandomXkcd returns a link to a random Xkcd comic.
func RandomXkcd() string { func RandomXkcd() string {
comicNum := fmt.Sprint(utils.GenerateRandomNumber(2468)) comicNum := fmt.Sprint(utils.GenerateRandomNumber(2468))
response, err := http.Get(fmt.Sprint("http://xkcd.com/" + comicNum + "/info.0.json")) response, err := http.Get(fmt.Sprint("http://xkcd.com/" + comicNum + "/info.0.json"))
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -31,6 +32,5 @@ func RandomXkcd() string {
json.Unmarshal(responseData, &responseObject) json.Unmarshal(responseData, &responseObject)
reply := fmt.Sprint("Random Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img) reply := fmt.Sprint("Random Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img)
return reply return reply
} }