From 23f67af24b944438d332250e36c21c92eae5372d Mon Sep 17 00:00:00 2001 From: Florian Baumann Date: Mon, 28 Nov 2022 16:47:56 +0100 Subject: [PATCH] Add card input validation --- src/serra/scryfall.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/serra/scryfall.go b/src/serra/scryfall.go index 5a07a4d..f9561b9 100644 --- a/src/serra/scryfall.go +++ b/src/serra/scryfall.go @@ -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 /, 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 {