42 lines
713 B
Go
42 lines
713 B
Go
|
package foodlist
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"encoding/csv"
|
||
|
"io"
|
||
|
"log"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
// FoodOfTheDay is the food list of the day
|
||
|
type FoodOfTheDay struct {
|
||
|
Date string
|
||
|
Foods []Food
|
||
|
}
|
||
|
|
||
|
// Food is a type of food
|
||
|
type Food struct {
|
||
|
Title string
|
||
|
Icon string
|
||
|
}
|
||
|
|
||
|
// GetFoodOfTheDay return the list of food of the day
|
||
|
func GetFoodOfTheDay(Today string) FoodOfTheDay {
|
||
|
foodcsv, _ := os.Open("foodlist/foods.csv")
|
||
|
foodreader := csv.NewReader(bufio.NewReader(foodcsv))
|
||
|
foods := FoodOfTheDay{}
|
||
|
for {
|
||
|
line, err := foodreader.Read()
|
||
|
if err == io.EOF {
|
||
|
break
|
||
|
} else if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
food := Food{line[0], line[1]}
|
||
|
foods.Foods = append(foods.Foods, food)
|
||
|
}
|
||
|
foods.Date = Today
|
||
|
|
||
|
return foods
|
||
|
}
|