foodoles/foodlist/foodlist.go

43 lines
735 B
Go
Raw Normal View History

2019-11-21 13:54:40 +01:00
package foodlist
import (
"bufio"
"encoding/csv"
"io"
"log"
"os"
2019-11-26 09:07:19 +01:00
"time"
2019-11-21 13:54:40 +01:00
)
// 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
2019-11-26 09:07:19 +01:00
func GetFoodOfTheDay() FoodOfTheDay {
2019-11-21 13:54:40 +01:00
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)
}
2019-11-26 09:07:19 +01:00
foods.Date = time.Now().Format("02/01/2006")
2019-11-21 13:54:40 +01:00
return foods
}