base safe

This commit is contained in:
2019-11-21 13:54:40 +01:00
parent faaf625fa8
commit 84227209ee
10 changed files with 132 additions and 114 deletions

41
foodlist/foodlist.go Normal file
View File

@ -0,0 +1,41 @@
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
}

8
foodlist/foods.csv Normal file
View File

@ -0,0 +1,8 @@
sandwich,🥪
sushi,🍣
burger,🍔
tacos,🌯
italien,🍝
kebab,🥙
pizza,🍕
hotdog,🌭
1 sandwich 🥪
2 sushi 🍣
3 burger 🍔
4 tacos 🌯
5 italien 🍝
6 kebab 🥙
7 pizza 🍕
8 hotdog 🌭