return errors

This commit is contained in:
Nick Griffey 2024-02-22 23:36:57 -06:00
parent 2925fb174c
commit bafbc3578c
1 changed files with 11 additions and 7 deletions

18
main.go
View File

@ -34,7 +34,6 @@ func formula(p float64) int64 {
}
func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
var event EventsRow
query := `
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
from events
@ -43,6 +42,7 @@ func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
limit 1
`
var event EventsRow
stmt, err := db.Prepare(query)
if err != nil {
return event, err
@ -53,20 +53,20 @@ func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
return event, err
}
func (event *EventsRow) Output() (int64, string, string) {
func (event *EventsRow) Output() (int64, string, string, error) {
timestamp, err := event.timestamp.Value()
if err != nil {
log.Fatal(err)
return 0, "", "", err
}
desc, err := event.description.Value()
if err != nil {
log.Fatal(err)
return 0, "", "", err
}
yearknown, err := event.yearknown.Value()
if err != nil {
log.Fatal(err)
return 0, "", "", err
}
var ago string
@ -78,7 +78,7 @@ func (event *EventsRow) Output() (int64, string, string) {
ago = date.String()
}
return timestamp.(int64), ago, desc.(string)
return timestamp.(int64), ago, desc.(string), nil
}
func main() {
@ -104,6 +104,10 @@ func main() {
log.Fatal(err)
}
timestamp, date, desc := event.Output()
timestamp, date, desc, err := event.Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v\t%v\t%v\n", timestamp, date, desc)
}