Add card input validation

This commit is contained in:
Florian Baumann 2022-11-28 16:47:56 +01:00
parent 0099fed6e6
commit d052e1a995

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
"strings"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
@ -156,6 +157,12 @@ type Set struct {
}
func fetch_card(path string) (*Card, error) {
if !strings.Contains(path, "/") {
err := errors.New(fmt.Sprintf("Card must follow format <set>/<number>, for example: ath/15"))
return &Card{}, err
}
// TODO better URL Building...
resp, err := http.Get(fmt.Sprintf("https://api.scryfall.com/cards/%s/", path))
if err != nil {