mirror-nourybot/pkg/api/numbersapi.go

43 lines
840 B
Go
Raw Normal View History

2021-10-17 21:37:45 +02:00
package api
import (
"fmt"
"io/ioutil"
"net/http"
log "github.com/sirupsen/logrus"
)
2021-10-20 23:21:13 +02:00
// RandomNumber returns a string containg fun facts about a random number.
// API used: http://numbersapi.com
2021-10-17 21:37:45 +02:00
func RandomNumber() string {
response, err := http.Get("http://numbersapi.com/random/trivia")
if err != nil {
2021-10-17 23:02:55 +02:00
log.Error(err)
2021-10-17 21:37:45 +02:00
}
2021-10-24 17:29:01 +02:00
2021-10-17 21:37:45 +02:00
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
2021-10-17 23:02:55 +02:00
log.Error(err)
2021-10-17 21:37:45 +02:00
}
return string(responseData)
}
2021-10-20 23:21:13 +02:00
// Number returns a string containing fun facts about a given number.
// API used: http://numbersapi.com
2021-10-17 21:49:28 +02:00
func Number(number string) string {
response, err := http.Get(fmt.Sprint("http://numbersapi.com/" + string(number)))
2021-10-24 17:29:01 +02:00
2021-10-17 21:37:45 +02:00
if err != nil {
2021-10-17 23:02:55 +02:00
log.Error(err)
2021-10-17 21:37:45 +02:00
}
2021-10-24 17:29:01 +02:00
2021-10-17 21:49:28 +02:00
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
2021-10-17 23:02:55 +02:00
log.Error(err)
2021-10-17 21:49:28 +02:00
}
2021-10-24 17:29:01 +02:00
2021-10-17 21:49:28 +02:00
return string(responseData)
2021-10-17 21:37:45 +02:00
}