Unmarshal card data into slice
This commit is contained in:
parent
4c8beb0eb5
commit
9fa8bb563f
|
@ -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.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue