Fix panic on scryfall error

This commit is contained in:
Artyom Belousov 2022-03-22 21:19:29 +03:00
parent ca0af01268
commit c6b0a150f1
2 changed files with 20 additions and 5 deletions

View file

@ -2,11 +2,12 @@ package cardsinfo
import (
"encoding/json"
"gitlab.com/flygrounder/go-mtg-vk/internal/dicttranslate"
"io/ioutil"
"net/http"
"net/url"
"strings"
"gitlab.com/flygrounder/go-mtg-vk/internal/dicttranslate"
)
const scryfallUrl = "https://api.scryfall.com"
@ -38,13 +39,16 @@ func applyFilters(name string) string {
}
func getCardByUrl(path string) string {
response, _ := http.Get(path)
response, err := http.Get(path)
if err != nil {
return ""
}
defer func() {
_ = response.Body.Close()
}()
data, _ := ioutil.ReadAll(response.Body)
var v card
err := json.Unmarshal(data, &v)
err = json.Unmarshal(data, &v)
if err != nil {
return ""
}