NewNote returns a new Note

This commit is contained in:
agatha 2024-05-12 14:45:04 -04:00
parent 4a006be08f
commit e7a78a4d33

17
main.go
View File

@ -48,6 +48,14 @@ type Note struct {
Text string `json:"text"` 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. // Reading holds the glucose and ketone level measurements along with the time the measurements were taken.
type Reading struct { type Reading struct {
Time time.Time `json:"time"` Time time.Time `json:"time"`
@ -145,10 +153,8 @@ func main() {
if err != nil { if err != nil {
fmt.Println("Error getting note: %s\n", err) fmt.Println("Error getting note: %s\n", err)
} else { } else {
appCtx.AddNote(Note{ note := NewNote(noteText)
Time: time.Now(), appCtx.AddNote(note)
Text: noteText,
})
} }
default: default:
fmt.Println("Quitting...") fmt.Println("Quitting...")
@ -156,6 +162,9 @@ func main() {
// Save Records before exiting // Save Records before exiting
err = appCtx.SaveRecords(recordsFilename) err = appCtx.SaveRecords(recordsFilename)
if err != nil {
fmt.Printf("Error saving records to file: %s\n", err)
}
} }
func getReading() (Reading, error) { func getReading() (Reading, error) {