Unmarshal card data into slice

This commit is contained in:
The Magician 2024-05-21 15:15:58 +01:00
parent 4c8beb0eb5
commit 9fa8bb563f
1 changed files with 15 additions and 2 deletions

View File

@ -2,7 +2,9 @@ package main
import ( import (
"database/sql" "database/sql"
"encoding/json"
"io" "io"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -157,6 +159,17 @@ func main() {
log.Printf("Bulk data has not been updated. Skipping download.") log.Printf("Bulk data has not been updated. Skipping download.")
} }
// Unmarshal cached file into Golang struct log.Printf("Unmarsaling file into slice...")
// Import cards into database allCardsBytes, err := ioutil.ReadFile(ALL_CARDS_CACHE_FILENAME)
check(err)
var allCards []types.Card
err = json.Unmarshal(allCardsBytes, &allCards)
check(err)
log.Printf("Unmarshaled file.")
log.Printf("Importing card data into database...")
err = operations.InsertCards(db, allCards)
check(err)
log.Printf("Imported card data.")
} }