Create cache directories

This commit is contained in:
The Magician 2024-05-21 12:28:08 +01:00
parent f31186add2
commit a01e591e5f
1 changed files with 19 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"log" "log"
"os"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/scryfall/methods" "sevenkeys/scryfall/methods"
) )
@ -19,6 +20,20 @@ func check(err error) {
} }
} }
func createCacheDirectories() error {
err := os.Mkdir(CACHE_DIR, os.ModePerm)
if err != nil && !os.IsExist(err) {
return err
}
err = os.Mkdir(SET_ICON_CACHE_DIR, os.ModePerm)
if err != nil && !os.IsExist(err) {
return err
}
return nil
}
func main() { func main() {
log.Println("Connecting to database...") log.Println("Connecting to database...")
db := database.GetDatabaseFromConfig("config.json") db := database.GetDatabaseFromConfig("config.json")
@ -29,8 +44,10 @@ func main() {
check(err) check(err)
log.Println("Downloaded set data.") log.Println("Downloaded set data.")
// Create cache dir log.Println("Creating cache directories...")
// Create icon cache dir err = createCacheDirectories()
check(err)
log.Println("Created cache directories.")
// Loop through sets, import set data into database and download icons // Loop through sets, import set data into database and download icons
// TODO: Only download icon if we don't already have the file // TODO: Only download icon if we don't already have the file