replace log.Fatalln with log.Error

This commit is contained in:
lyx0 2021-10-19 15:33:23 +02:00
parent 0762145c2f
commit 07eb4090c5
6 changed files with 23 additions and 18 deletions

View file

@ -4,8 +4,9 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
log "github.com/sirupsen/logrus"
)
// https://api.ivr.fi
@ -17,14 +18,14 @@ type uidApiResponse struct {
func Userid(username string) string {
resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/resolve/%s", username))
if err != nil {
log.Fatalln(err)
log.Error(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
log.Error(err)
}
var responseObject uidApiResponse

View file

@ -3,8 +3,9 @@ package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
log "github.com/sirupsen/logrus"
)
type randomCatResponse struct {
@ -14,12 +15,12 @@ type randomCatResponse struct {
func RandomCat() string {
response, err := http.Get("https://aws.random.cat/meow")
if err != nil {
log.Fatalln(err)
log.Error(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
log.Error(err)
}
var responseObject randomCatResponse

View file

@ -3,8 +3,9 @@ package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
log "github.com/sirupsen/logrus"
)
type randomDogResponse struct {
@ -14,12 +15,12 @@ type randomDogResponse struct {
func RandomDog() string {
response, err := http.Get("https://random.dog/woof.json")
if err != nil {
log.Fatalln(err)
log.Error(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
log.Error(err)
}
var responseObject randomDogResponse

View file

@ -3,8 +3,9 @@ package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
log "github.com/sirupsen/logrus"
)
type randomFoxResponse struct {
@ -15,12 +16,12 @@ type randomFoxResponse struct {
func RandomFox() string {
response, err := http.Get("https://randomfox.ca/floof/")
if err != nil {
log.Fatalln(err)
log.Error(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
log.Error(err)
}
var responseObject randomFoxResponse

View file

@ -4,10 +4,10 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/lyx0/nourybot/pkg/utils"
log "github.com/sirupsen/logrus"
)
type XkcdResponse struct {
@ -20,11 +20,11 @@ func RandomXkcd() string {
comicNum := fmt.Sprint(utils.GenerateRandomNumber(2468))
response, err := http.Get(fmt.Sprint("http://xkcd.com/" + comicNum + "/info.0.json"))
if err != nil {
log.Fatalln(err)
log.Error(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
log.Error(err)
}
var responseObject XkcdResponse
json.Unmarshal(responseData, &responseObject)

View file

@ -4,18 +4,19 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
log "github.com/sirupsen/logrus"
)
func Xkcd() string {
response, err := http.Get("https://xkcd.com/info.0.json")
if err != nil {
log.Fatalln(err)
log.Error(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
log.Error(err)
}
var responseObject XkcdResponse
json.Unmarshal(responseData, &responseObject)