implement AppConfig and refactored AppContext

This commit is contained in:
agatha 2024-05-12 15:54:36 -04:00
parent 1874a875f5
commit 796075d9f2

12
main.go
View File

@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"ketotrack/config"
"ketotrack/data"
"ketotrack/model"
)
@ -38,9 +39,14 @@ func init() {
}
func main() {
var appCtx data.AppContext
appConfig := config.Load()
appCtx, err := data.NewContext(appConfig.DataPath)
if err != nil {
fmt.Printf("Error initializing application context: %s\n", err)
return
}
if err := appCtx.LoadRecords(recordsFilename); err != nil {
if err := appCtx.LoadRecords(); err != nil {
fmt.Printf("Error loading records from file: %s\n", err)
}
@ -79,7 +85,7 @@ func main() {
}
// Save Records before exiting
if err := appCtx.SaveRecords(recordsFilename); err != nil {
if err := appCtx.SaveRecords(); err != nil {
fmt.Printf("Error saving records to file: %s\n", err)
}
}