package main import ( "encoding/json" "net/http" "net/url" "time" ) type CardSearchResults struct { TotalCards int `json:"total_cards"` HasMore bool `json:"has_more"` Data []CardData `json:"data"` NextPage string `json:"next_page"` } type CardData struct { ID string `json:"id"` Name string `json:"name"` URI string `json:"uri"` ScryfallURI string `json:"scryfall_uri"` Layout string `json:"layout"` HighresImage bool `json:"highres_image"` ImageUris struct { Small string `json:"small"` Normal string `json:"normal"` Large string `json:"large"` Png string `json:"png"` ArtCrop string `json:"art_crop"` BorderCrop string `json:"border_crop"` } `json:"image_uris"` Eur string `json:"eur"` EdhrecRank int `json:"edhrec_rank"` RelatedUris struct { Gatherer string `json:"gatherer"` TcgplayerDecks string `json:"tcgplayer_decks"` Edhrec string `json:"edhrec"` Mtgtop8 string `json:"mtgtop8"` } `json:"related_uris"` PurchaseUris struct { Amazon string `json:"amazon"` Ebay string `json:"ebay"` Tcgplayer string `json:"tcgplayer"` Magiccardmarket string `json:"magiccardmarket"` Cardhoarder string `json:"cardhoarder"` CardKingdom string `json:"card_kingdom"` MtgoTraders string `json:"mtgo_traders"` Coolstuffinc string `json:"coolstuffinc"` } `json:"purchase_uris"` } var netClient = &http.Client{ Timeout: time.Second * 10, } func scryfallSearch(query string) (results CardSearchResults, err error) { query = url.QueryEscape(query) response, err := netClient.Get("https://api.scryfall.com/cards/search?order=name&q=" + query) if err != nil { return } defer response.Body.Close() err = json.NewDecoder(response.Body).Decode(&results) return }