mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
42 lines
751 B
Go
42 lines
751 B
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
"strconv"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
func RandomNumber() string {
|
||
|
response, err := http.Get("http://numbersapi.com/random/trivia")
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
responseData, err := ioutil.ReadAll(response.Body)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
|
||
|
return string(responseData)
|
||
|
}
|
||
|
|
||
|
func Number(num string) string {
|
||
|
number, err := strconv.Atoi(num)
|
||
|
if err != nil {
|
||
|
return "Given value is not a number."
|
||
|
} else {
|
||
|
response, err := http.Get(fmt.Sprint("http://numbersapi.com/" + string(number)))
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
responseData, err := ioutil.ReadAll(response.Body)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
return string(responseData)
|
||
|
}
|
||
|
|
||
|
}
|