split output code into method
This commit is contained in:
28
main.go
28
main.go
@@ -52,6 +52,22 @@ func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
|
|||||||
return event, err
|
return event, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (event *EventsRow) Output() (int64, string, string) {
|
||||||
|
timestamp, err := event.timestamp.Value()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
desc, err := event.description.Value()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
date := time.Unix(timestamp.(int64), 0)
|
||||||
|
|
||||||
|
return timestamp.(int64), date.String(), desc.(string)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
percent := flag.Float64("p", -1, "percentage")
|
percent := flag.Float64("p", -1, "percentage")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -75,16 +91,6 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamp, err := event.timestamp.Value()
|
timestamp, date, desc := event.Output()
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
desc, err := event.description.Value()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
date := time.Unix(timestamp.(int64), 0)
|
|
||||||
fmt.Printf("%v\t%v\t%v\n", timestamp, date, desc)
|
fmt.Printf("%v\t%v\t%v\n", timestamp, date, desc)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user