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) {