From e7a78a4d33604497f38a4b53a6774dcacad63230 Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 12 May 2024 14:45:04 -0400 Subject: [PATCH] NewNote returns a new Note --- main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d714d49..973d8ad 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,14 @@ type Note struct { Text string `json:"text"` } +// NewNote returns a new Note +func NewNote(text string) Note { + return Note{ + Time: time.Now(), + Text: text, + } +} + // Reading holds the glucose and ketone level measurements along with the time the measurements were taken. type Reading struct { Time time.Time `json:"time"` @@ -145,10 +153,8 @@ func main() { if err != nil { fmt.Println("Error getting note: %s\n", err) } else { - appCtx.AddNote(Note{ - Time: time.Now(), - Text: noteText, - }) + note := NewNote(noteText) + appCtx.AddNote(note) } default: fmt.Println("Quitting...") @@ -156,6 +162,9 @@ func main() { // Save Records before exiting err = appCtx.SaveRecords(recordsFilename) + if err != nil { + fmt.Printf("Error saving records to file: %s\n", err) + } } func getReading() (Reading, error) {