43 lines
735 B
Go
43 lines
735 B
Go
package foodlist
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/csv"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// 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() 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 = time.Now().Format("02/01/2006")
|
|
|
|
return foods
|
|
}
|