From 72601b87ef040a3c6882368ac85c12c1ae705cd2 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 21 Oct 2024 21:30:12 +0200 Subject: model: Refactor public API of DB This commit makes not externally needed methods private and adds error return values since something like log.Fatal() should be called outside this package since it is control-flow-related. --- main.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 1d7d3e1..55425e4 100644 --- a/main.go +++ b/main.go @@ -34,15 +34,29 @@ func main() { } log.Printf("Storage directory: %s\n", storage.Path) - db := model.OpenDB(filepath.Join(storage.Path, "ceres.sqlite3")) - defer db.Close() - err := db.Migrate() + db, err := model.OpenDB(filepath.Join(storage.Path, "ceres.sqlite3")) + if err != nil { + log.Fatalf("Failed to open database: %v", err) + } + defer func() { + err := db.Close() + if err != nil { + log.Println("Failed to close database") + } else { + log.Println("Closed database") + } + }() + + err = db.Migrate() if err != nil { log.Fatal(err) } if flags.examples { - db.CreateExamples() + err := db.CreateExamples() + if err != nil { + log.Fatalf("Failed to insert example recipes: %v", err) + } log.Println("Created example recipes") } -- cgit v1.2.3-70-g09d2