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 (
"database/sql"
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"os"
@ -157,6 +159,17 @@ func main() {
log.Printf("Bulk data has not been updated. Skipping download.")
}
// Unmarshal cached file into Golang struct
// Import cards into database
log.Printf("Unmarsaling file into slice...")
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.")
}